FAQ Database Discussion Community


How to draw text of multiple sizes aligned on line with TextRenderer? [duplicate]

c#,winforms,drawing,gdi,text-rendering
This question already has an answer here: How do I get the position of the text baseline in a Label and a NumericUpDown? 2 answers I have an array of classes that contains some text and a font. I want to draw all the text aligned on line independently...

What does ToolStripProfessionalRenderer.OnRenderItemBackground do?

c#,winforms,gdi,renderer,toolstrip
I am writing a custom ToolStripProfessionalRenderer component and currently working through all of the OnRender... overrides. This one in particular has stumped me: OnRenderItemBackground I can't see it drawing anything, so to force it to draw something I've done this: protected override void OnRenderItemBackground(ToolStripItemRenderEventArgs e) { e.Graphics.FillRectangle(Brushes.Red, e.Item.ContentRectangle); } ...but...

Changing the background color of AutoComplete DropDownList of TextBox

c#,control,gdi
How can I change the background color of the autocomplete dropdown list of a textbox? I have searched a lot but have not found any proper solution. The existing solutions use a panel or some other control to mimic the behavior of autocomplete but I want to change the color...

picture box crossed out C#

c#,graphics,2d,picturebox,gdi
I have a project in which I draw several rectangles using GDI. I do it using i++ from i=0 to i<=10. I use e.Graphics.FillRectangles. I refresh the drawn rectangles every 1/10s by calling Graphics.Invalidate() My problem is that my picture box gets crossed out when drawing more the 4 rectangles....

Custom draw dropdown panel outside Control bounds

c#,winforms,graphics,gdi+,gdi
I seem to have picked up an "unclear what I'm asking" vote. I want to custom draw a combo box style control. The pop open section needs to draw outside the bounds of the control itself. I cannot use combo box - think something similar to the gallery control in...

multiple screen capture with MSDN library

c++,winapi,gdi,screen-capture
I am working on screen capture with multiple display units. As GetDesktopWindow() only gets the handle to primary monitors, I tried to use EnumDisplayMonitors() to do the job. After reading the MSDN website, I wrote these in the main(): HDC hdc = GetDC(NULL); EnumDisplayMonitors(hdc, NULL, MyCapScreenEnumProc, 0); ReleaseDC(NULL, hdc); And...

Setting and connecting pixels

mfc,gdi
I want to set pixels where the mouse click is made and connect those pixels. My code is as follows. void CChildView::OnLButtonDown(UINT nFlags,CPoint point) { CDC* pDC= GetDC(); int x[100],y[100]; POINT Pt[4]; for(int i=0;i<4;i++) { SetPixel(NULL,Pt[i].x,Pt[i].y,RGB(0,0,0)); pDC->MoveTo(Pt[i].x,Pt[i].y); pDC->LineTo(Pt[i+1].x,Pt[i+1].y); } } But I am not getting anything in the output other...

Template matching from a screenshot of a window

c++,opencv,computer-vision,gdi,template-matching
What I've done I have a small template image which is meant to be used to find coordinates of matching subimages within a larger screenshot image. The screenshot itself is captured into a memory DC with the help of BitBlt, then converted into a cv::Mat via GetDIBits, like so: HDC...

How to draw RGB pixel data from memory with GDI in C++

c++,windows,gdi
I have a pointer to RGB data (640x480x3 bytes) that I want to draw into a window using BitBlt or something else equally fast. How do I convert the RGB data into something usable with BitBlt (for example). Here is what I tried so far (without success) unsigned char *buf...

Is there a difference in disposing Icon and Bitmap?

c#,winforms,gdi,resource-leak
I was debugging resource leaks in my application and created a test app to test GDI object leaks. In OnPaint I create new icons and new bitmaps without disposing them. After that I check the increase of GDi objects in task manager for each of the cases. However, if I...

Error while writing Date to Image MetaData in C#-String was not recognized as a valid DateTime

c#,image,date,metadata,gdi
Im trying to write metadata to images using the following code.But when i try to add the date field an error is thrown String was not recognized as a valid DateTime using (Stream bitmapStream = File.Open(fileName, FileMode.Open, Here Date is the value obtained from DatePicker. date.tostring()->29/01/2015 06:35:13 PM date.ToShortDateString()-> 29/01/2015...

make GDI drawing more efficient C#

c#,gdi
At the moment my code takes about 10% of my CPUs power. How can I make it more efficient and less flickerish? Code: private void timer1_Tick(object sender, EventArgs e) { DrawLocal(); Thread.Sleep(17); pictureBox1.Invalidate(); } private void DrawLocal() { int localReadX = ReadAddress("hl2", "client.dll+0xBFFF00 364 0"); int localReadY = ReadAddress("hl2", "client.dll+0xBFFF00...

GDI Overall Clipping Bounds

c#,winforms,graphics,gdi+,gdi
Does GDI have any method of setting an overall clipping area, in the same way the GDI+ Graphics object does? Specifically: Graphics.DrawString uses GDI+ which includes the clipping bounds system. TextRenderer.DrawText uses GDI which does not. My new scrollbar system automatically resizes the Graphics draw area as needed. While tidying...

A generic error occurred in GDI+ when saving Image

c#,gdi,system.drawing.graphics
I read the answer for the same question and did whatever is asked to do. I also gave the write permission to the folder for current user as mentioned in one of the previous answer but still getting this error. So Please can anyone provide me the specific answer what...

Graphics.DrawPath and LinearGradientBrush issue

c#,winforms,gdi+,gdi,lineargradientbrush
In relation to this question that I asked a few weeks ago now LinearGradientBrush does not render correctly Consider the following code: protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Rectangle rect = new Rectangle(100, 100, 200, 100); using(LinearGradientBrush brush = new LinearGradientBrush(rect, Color.Red, Color.Blue, 90)) { using(Pen pen = new...

How much improvement can I expect with SharpDX over heavily optimized GDI code in C#/WinForms?

c#,windows,winforms,gdi,sharpdx
I've been working on a C#/GDI graphical app for a couple years. I've spent a lot of time optimizing the drawing code. I am drawing to the screen by invalidating a PictureBox control about 10 times a second, and by leveraging subsequent OnPaint event that occurs when Windows triggers it....

Drawing by Windows GDI inside of Qt

qt,drawing,gdi,qgraphicsview
I am trying to use Windows GDI inside of QGraphicsView paintEvent but have noticed some drawing issues, for example the drawing disappear or blinking when I resize window or minimize and maximize. When I use Qt instead of GDI its working perfectly. Here is the code: [UPDATED CODE] #include "CustomView.h"...

Custom richtextbox control kerning issues

c#,.net,winforms,gdi,kerning
Okay, so I have been working on something for a little while and I have gotten to the point where I am planning the Text rendering part. I can already draw strings of text in two ways; DrawString and TextRenderer.DrawText. I prefer DrawText since measuring text is more accurate when...

Transparency in GDI DCs

c++,winapi,gdi
I have the "simple" goal of drawing a bitmap with some transparency around it on the screen. That bit wasn't so hard: #include <windows.h> #include "BBKG.h" HINSTANCE hInst; LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); static int wH = 156; static int wW = 166; HBITMAP CreateBitmapMask(HBITMAP hbmColour, COLORREF crTransparent) {...

DrawParentBackground / DrawThemeParentBackground on a top level form

c#,winforms,gdi+,gdi
Consider the following example. This was done by setting the TransparencyKey property: public Form() { this.InitializeComponent(); this.BackColor = Color.Fuscia; this.TransparencyKey = this.BackColor; } What I actually want to be able to do is similar to the behavior of the DrawThemeParentBackground function (conveniently wrapped up in .NET as DrawParentBackground), however this...

winapi: from HDC to an HBITMAP

c++,winapi,bitmap,gdi
I would like to do something which I believe is fairly simple but since I am new to the winapi I am finding a lot of problems. Basically I have an HDC (which I am BitBlitting from a loaded Bitmap) and I am drawing a rectangle on it. Then I...