Questions tagged [onpaint]

An event that is triggered when a GUI component needs to be repainted

onPaint is the method responsible for performing the paint act triggered from a PaintEvent. This event is triggered when a GUI component needs to be repainted, usually as a result of a change to the underlying data behind the GUI component. onPaint is responsible for the physical display of the component, and in particular, applying the themes and colors appropriate for the application/output device.

198 questions
15
votes
4 answers

How to effectively draw on desktop in C#?

I want to draw directly on the desktop in C#. From searching a bit, I ended up using a Graphics object from the Desktop HDC (null). Then, I painted normally using this Graphics object. The problem is that my shapes get lost when any part of the…
Lazlo
  • 8,518
  • 14
  • 77
  • 116
10
votes
4 answers

What is the proper way to draw a line with mouse in C#

This is my drawing code to draw a custom line with mouse onto a Chart. Can you please help me to do it proper way ? namespace Grafi { public partial class Form1 : Form { bool isDrawing = false; Point…
Primoz
  • 4,079
  • 17
  • 56
  • 67
8
votes
1 answer

Why OnPaint is not called anymore if it fails to load a picture once?

I found something that I do not really get: protected override void OnPaint(PaintEventArgs e) { DrawChar(e.Graphics); base.OnPaint(e); } void DrawChar(Graphics g) { if (body != null) { g.DrawImage(body, X, Y); …
John V
  • 4,855
  • 15
  • 39
  • 63
7
votes
1 answer

Drawing an image onto a Panel control gives artefacts when resizing

Currently I'm trying to do what I thought would be a simple task: Draw an image onto the full area of a Panel control in Windows Forms. (Please ignore for the moment that I could use the BackgroundImage property) The image to draw looks like…
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
7
votes
3 answers

How to avoid screen flickering when showing form with user drawn controls?

So the transparent background problem is solved. Now, every time I show the form (or have to have it repainted), I get a lot of flickering. Is there any way I can not update the screen until the paint event is complete, or any other way to stop…
user29140
  • 187
  • 2
  • 9
7
votes
5 answers

C#: Overriding OnPaint on ProgressBar not working?

Was thinking it should be pretty easy to create a ProgressBar that drew some text upon itself. However, I am not quite sure what is happening here... I added the following two overrides: protected override void OnPaintBackground(PaintEventArgs…
Svish
  • 152,914
  • 173
  • 462
  • 620
6
votes
3 answers

Why is DrawString exhibiting unexpected behavior in C# Winforms?

I have subclassed a control in C# WinForms, and am custom drawing text in my OnPaint() handler. The font is set to Courier New using the following code in my form: FontFamily family = new FontFamily("Courier New"); this.myControl.Font = new…
Ko9
  • 199
  • 1
  • 3
  • 9
6
votes
3 answers

Populating a FlowLayoutPanel with a large number of controls and painting thumbnails on demand

I'm trying to make an ImageListBox kind of control that will display a large numbers of thumbnails, like the one that Picasa uses. This is my design: I have a FlowLayoutPanel that is populated with a lot of UserControl objects, for example…
everwicked
6
votes
2 answers

C# WinForms - Paint method questions

I am not sure what is the best way of using graphics - should I attach my classes to main form Paint event and then do the drawing, or it is better to call it from overidden OnPaint void like this? I mean, is it OK to do that like this: protected…
Thomas
  • 2,575
  • 9
  • 31
  • 41
5
votes
1 answer

Controls not being drawn at the same time

I have a form which I'm bringing up using ShowDialog which contains a couple of text boxes, labels and a button. The problem I'm having is that the text boxes are being drawn before the form itself and the other controls are drawn. I am overriding…
Jurgen Camilleri
  • 3,559
  • 20
  • 45
5
votes
1 answer

Lag between Scroll event and Paint event and maybe something inbetween

I have a simple panel on a form and I'm using AutoScrollMinSize and AutoScroll to get some scrollbars on my panel, all works OK. I also have a Scroll event which I use to invalidate the whole panel area, as defacto it seems to only invalidate bits…
Niksan
  • 149
  • 1
  • 9
5
votes
2 answers

How to use the OnPaint event in C#?

i saw some similar questions on the site but none of them really helped me. I have a function that draws a few lines on the form when a button is clicked that vary in shape depending on the values the user enters in some textboxes. My problem is…
Stefan Manciu
  • 490
  • 1
  • 6
  • 19
4
votes
1 answer

Best practice for OnPaint, Invalidate, Clipping and Regions

I have a User Control with completely custom drawn graphics of many objects which draw themselves (called from OnPaint), with the background being a large bitmap. I have zoom and pan functionality built in, and all the coordinates for the objects…
Trevor Elliott
  • 11,292
  • 11
  • 63
  • 102
4
votes
3 answers

TextBox OnPaint method is not called?

I have use the following code to create a textbox, but the paint method is not triggered at any situation of the textbox. Can you suggest a solution to trigger the OnPaint() ? public class MyTextBox : TextBox { protected override void…
Venkatesh Ks
  • 92
  • 1
  • 7
4
votes
6 answers

Why is my c# paint method running out of memory?

I'm new to c#, and trying to learn by writing some simple apps to get familiar with the syntax and .NET library. The most recent miniproject I took on is a polar clock like the one found here. One of the problems I noticed early on was that the app…
Dereleased
  • 9,939
  • 3
  • 35
  • 51
1
2 3
13 14