- In the extension bar, click the AdBlock Plus icon
- Click the large blue toggle for this website
- Click refresh
- In the extension bar, click the AdBlock icon
- Under "Pause on this site" click "Always"
- In the extension bar, click on the Adguard icon
- Click on the large green toggle for this website
- In the extension bar, click on the Ad Remover icon
- Click "Disable on This Website"
- In the extension bar, click on the orange lion icon
- Click the toggle on the top right, shifting from "Up" to "Down"
- In the extension bar, click on the Ghostery icon
- Click the "Anti-Tracking" shield so it says "Off"
- Click the "Ad-Blocking" stop sign so it says "Off"
- Refresh the page
- In the extension bar, click on the uBlock Origin icon
- Click on the big, blue power button
- Refresh the page
- In the extension bar, click on the uBlock icon
- Click on the big, blue power button
- Refresh the page
- In the extension bar, click on the UltraBlock icon
- Check the "Disable UltraBlock" checkbox
- Please disable your Ad Blocker
- Disable any DNS blocking tools such as AdGuardDNS or NextDNS
- Disable any privacy or tracking protection extensions such as Firefox Enhanced Tracking Protection or DuckDuckGo Privacy.
If the prompt is still appearing, please disable any tools or services you are using that block internet ads (e.g. DNS Servers, tracking protection or privacy extensions).
Question
+FloatingFatMan Subscriber¹
Recently, while writing my own custom button, I needed to convert the TextAlign property to something I can use in DrawString. This initially proofed not as simple as I thought because TextAlign uses the ContentAlignment type, and DrawString uses the far simple StringAlignment.
I spent a good half a day scouring the internet, and I really couldn't believe what I found. It seems that the ONLY way that anyone had found how to do this relatively simple task, was with a switch statement! Laboriously checking which TextAlignment was being used, and manually setting the .LineAlignment and .Alignment properties of the StringFormat object before sending it to graphics.DrawString.
Experience has taught me that, in C#, there are usually many solutions that will work, but most of them are complete and utter garbage, and it struck me that there's no way that a long assed switch statement was the right solution. So I had a look at the actual values of the enums for ContentAlignment and StringAlignment, and realised that really, the solution is actually very simple; you just need to use a little math.
Convert ContentAlignment to StringAlignment
StringFormat cFormat; Int32 lNum = (Int32)Math.Log((Double)this.TextAlign, 2); cFormat.LineAlignment = (StringAlignment)(lNum / 4); cFormat.Alignment = (StringAlignment)(lNum % 4);
...you then just use the cFormat object in your DrawString.
That's it! Simple really, isn't it?
Link to comment
https://www.neowin.net/forum/topic/1060552-c-tip-converting-contentalignment-to-stringalignment/Share on other sites
3 answers to this question
Recommended Posts