gdi+

Trigger event on trackbar ValueChanged, but not in code

左心房为你撑大大i 提交于 2019-12-06 00:19:06
I want to be able to modify the value property of a trackbar in code without triggering my event handler. I wish to trigger the event only when the control is changed by the user by dragging the slider or moving it with the keyboard. What's the simplest way of achieving this? I have 6 trackbars and I want to change the value of 3 of them depending on which trackbar is changed. The issue is that changing the value of those trackbars will trigger their ValueChanged events. One way you can do this is to temporarily remove the event handlers before you modify the values in code, and then reattach

TextRenderer with Graphics transform

心已入冬 提交于 2019-12-05 23:59:49
I've been working on a custom control and I've run into an issue with TextRenderer acting a bit surprisingly. In my OnPaint event I apply transform to the Graphics object to compensate for the scroll position like this: e.Graphics.Transform = new System.Drawing.Drawing2D.Matrix(1, 0, 0, 1, this.AutoScrollPosition.X, this.AutoScrollPosition.Y); Then I pass the graphic object to all sub elements of the control so that they paint themselves onto it. One of this elements should draw text string onto the graphics surface. And this is where I've got an issue. This line seems to work correctly when

The text is too bold by DrawString on C#

戏子无情 提交于 2019-12-05 22:37:26
I have use GDI DrawString method to draw text. When the program is running, the text on the screen seems very good, however once I saved the files to image, the font will be bolder than before. The normal will be bold, the bold will be much bolder. How to deal with this? public override void DrawTo(Graphics g, int x, int y, int flag) { if (flag == 1) { Pen dpen = new Pen(Color.FromArgb(128, 0, 0, 0), 1); dpen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot; g.DrawRectangle(dpen, new Rectangle(Bounds.X + x, Bounds.Y + y, Bounds.Width, Bounds.Height)); } if (!string.IsNullOrEmpty(Text)) {

Font size discrepancy in .NET GDI+?

别说谁变了你拦得住时间么 提交于 2019-12-05 21:34:45
问题 I am wracking my brains in trying to understand the discrepancy between the font sizes users select or specify (for example, using a FontDialog ) and the em-size reported by the Font class in .NET. For example: using (FontDialog dlg = new FontDialog()) { if (dlg.ShowDialog() == DialogResult.OK) { Console.WriteLine("Selected font size: " + dlg.Font.SizeInPoints.ToString("0.##")); } } Using the above code, you will get some confusing results: Selecting 11 in the dialog produces 11.25 Selecting

I'm experiencing unexpected results from Graphics.DrawImage

£可爱£侵袭症+ 提交于 2019-12-05 19:07:51
To reproduce this issue, please create a 2x2 pixel black image in Microsoft Paint, saved as D:\small.png . Then create a new WinForms app in Visual Studio, with a no-margin PictureBox. Then use the following code: void f6(Graphics g) { var img = Image.FromFile(@"d:\small3.png"); var srcRect = new Rectangle(0, 0, img.Width, img.Height); int factor = 400; var destRect = new Rectangle(0, 0, img.Width * factor, img.Height * factor); g.DrawRectangle(new Pen(Color.Blue), destRect); g.DrawImage(img, destRect, srcRect, GraphicsUnit.Pixel); } void pictureBox1_Paint(object sender, PaintEventArgs e) { f6

An unclear converted image. wmf to png

安稳与你 提交于 2019-12-05 18:29:52
I'm trying to convert wmf image file into png format with c#.net. But, saved image is unclear. my code: Metafile img = new Metafile(@"test.wmf"); MetafileHeader header = img.GetMetafileHeader(); Bitmap bitmap = new Bitmap((int)(img.Width / header.DpiX * 100), (int)(img.Height / header.DpiY * 100)); using(Graphics g = Graphics.FromImage(bitmap)){ g.DrawImage(img, 0, 0); } bitmap.Save("test.png", ImageFormat.Png); How could I get it clear? The .wmf file has extremely large values for DpiX/Y. You'll need to rescale the image to make it a better fit with the resolution of your monitor. This code

.net onpaint vertical sync

放肆的年华 提交于 2019-12-05 16:53:09
I'm trying to implement some animation using winforms and gdi+, but I get a lot of tearing moving sprites inside a control. Is there a way in managed .net to have the overriden Control.OnPaint method wait for the vertical retrace of the monitor? Are you already using double buffering? If not I would suspect that would remove the tearing, and it is simpler than trying to wait for the vertical retrace. 来源: https://stackoverflow.com/questions/819762/net-onpaint-vertical-sync

Halftone effect in with gdi+

南楼画角 提交于 2019-12-05 16:49:49
How would I go about mimicking this halftone effect in GDI+? It almost looks like Floyd–Steinberg dithered version of the image overlaying a full one but I'm not convinced. I gave this a try and got this result: It may be a place to start. I did it like this: Draw the original picture with low saturation (using a color matrix) Draw the original image onto 1) with high saturation using a pattern mask (ie the dots) I created the pattern mask like this: using (var g = Graphics.FromImage(bmpPattern)) { g.Clear(Color.Black); g.SmoothingMode = SmoothingMode.HighQuality; for (var y = 0; y < bmp

Desktop screen overlay - new form flicker issue

℡╲_俬逩灬. 提交于 2019-12-05 15:12:48
As part of my open source DeskPins clone (two separate links, one for original, one for clone on GitHub), I need to allow user to interact with desktop. I figured the easiest way would be opening a new form and paint desktop contents on top of it. Then I should be able to easily set mouse cursor and give visual cues to user about windows that is currently in focus. A more complicated alternative would be using p/invoke to SetSystemCursor and injecting custom code in other window's WM_PAINT event queue (and potentially other WinApi related work, for example, cursor cleaning would be an issue,

Fast way to draw lines using different Color using GDI+?

寵の児 提交于 2019-12-05 14:32:39
I have an dynamic List of Point, new Point can be added at any time. I want to draw lines to connect them using different color. Color is based on the index of those points. Here is the code: private List<Point> _points; private static Pen pen1 = new Pen(Color.Red, 10); private static Pen pen2 = new Pen(Color.Yellow, 10); private static Pen pen3 = new Pen(Color.Blue, 10); private static Pen pen4 = new Pen(Color.Green, 10); private void Init() { // use fixed 80 for simpicity _points = new List<Point>(80); for (int i = 0; i < 80; i++) { _points.Add(new Point(30 + i * 10, 30)); } } private void