Click here to Skip to main content
15,919,434 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: how to press a button from a other applicationt ? Pin
Steven J Jowett24-Aug-09 4:30
Steven J Jowett24-Aug-09 4:30 
QuestionCrystal Report 10: Report Footer Pin
C#Coudou23-Aug-09 20:05
C#Coudou23-Aug-09 20:05 
AnswerRe: Crystal Report 10: Report Footer Pin
Paramu197323-Aug-09 23:26
Paramu197323-Aug-09 23:26 
QuestionRun Time Design Image Pin
Anubhava Dimri23-Aug-09 19:31
Anubhava Dimri23-Aug-09 19:31 
AnswerRe: Run Time Design Image Pin
Christian Graus23-Aug-09 21:22
protectorChristian Graus23-Aug-09 21:22 
GeneralRe: Run Time Design Image Pin
Dave Kreskowiak24-Aug-09 3:35
mveDave Kreskowiak24-Aug-09 3:35 
GeneralRe: Run Time Design Image Pin
Nagy Vilmos24-Aug-09 3:59
professionalNagy Vilmos24-Aug-09 3:59 
AnswerRe: Run Time Design Image Pin
Luc Pattyn24-Aug-09 5:59
sitebuilderLuc Pattyn24-Aug-09 5:59 
Hi,

here are two bits of information for you:

1.
there are several relevant articles here on CodeProject (e.g. search for Paint.NET)

2.
I have a standard reply for such questions, here it goes (example code is C#, VB.NET would be similar):

there are several steps to correctly draw something; it does not matter how complex the paint job is: from a single line, to a complex drawing, or a real work of art.

To make sure it all becomes visible on the screen and gets repainted automatically when moving, resizing, minimizing/maximizing/restoring or uncovering your Form, one should follow these steps:

1.
decide upon what object you want to draw; it normally is a Control (e.g. a Panel) or a Form itself. I prefer to add a Panel to a Form, then draw on the Panel. And I do not like PictureBoxes, they are pretty useless.

2.
create some variables (Rectangle, struct, class, whatever) that hold the parameters of your drawing. For a rectangle that could be top and left coordinate, and width+height, or just a Rectangle. etc. For a complex drawing, it could be a List of objects that derive of a common type, each having its own PaintMe() method.

3.
create a Paint handler (either add your own paint handler to the Paint event, or override the OnPaint method) for that Panel, and do all your drawing in there, using the Graphics object inside the PaintEventArgs, and your variables. Do not call CreateGraphics!

4.
if and when you want to change things, modify the variables and call Panel.Invalidate() or one of its overloads (for selective invalidation).

5.
If you want to animate things, perform the move (step 4) inside the Tick handler of a Windows.Forms.Timer which ticks on the GUI thread, so you are allowed to call Invalidate() from there too.

BTW: if you need to create some objects (Fonts, Pens, Brushes, ...) either keep them
alive in class members (hence create them only once); or create them inside the Paint
handler and don't forget to call Dispose() on them.

C# example:
private Panel panel;
private bool paintRectFlag=true;
private Rectangle rect=new Rectangle(20, 20, 300, 200);
private Pen rectPen=Pens.Black;

public Form1() {
    InitializeComponents();
    panel=new Panel();
    panel.Bounds=new Rectangle(…);
    panel.Paint+=panelPaintHandler;
    Controls.Add(panel);
}

protected void panelPaintHandler(object sender, PaintEventArgs e) {
    Graphics g=e.Graphics;
    if (paintRectFlag) g.DrawRectangle(rectPen, rect);
}

protected void buttonClickHandler(object sender, EventArgs e) {
    paintRectFlag=!paintRectFlag;   // toggle visible flag
    panel.Invalidate();
}



Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.

Questionhow to mention paper size in pragmatically ? [modified] Pin
JC.KaNNaN23-Aug-09 19:29
JC.KaNNaN23-Aug-09 19:29 
QuestionServices Management Visual Basic Pin
Dennis Huisman23-Aug-09 0:12
Dennis Huisman23-Aug-09 0:12 
AnswerRe: Services Management Visual Basic Pin
Luc Pattyn23-Aug-09 0:51
sitebuilderLuc Pattyn23-Aug-09 0:51 
GeneralRe: Services Management Visual Basic Pin
Dennis Huisman23-Aug-09 20:31
Dennis Huisman23-Aug-09 20:31 
GeneralRe: Services Management Visual Basic Pin
Dennis Huisman1-Sep-09 4:54
Dennis Huisman1-Sep-09 4:54 
QuestionVb 6 and Crystal Reports 8 Pin
sivaraman_sankaranarayanan22-Aug-09 21:27
sivaraman_sankaranarayanan22-Aug-09 21:27 
AnswerRe: Vb 6 and Crystal Reports 8 Pin
Christian Graus23-Aug-09 1:14
protectorChristian Graus23-Aug-09 1:14 
AnswerRe: Vb 6 and Crystal Reports 8 Pin
εїзεїзεїз23-Aug-09 1:45
εїзεїзεїз23-Aug-09 1:45 
QuestionHow do I programmatically add data to a report - and how do I draw the report? Pin
BluesEnd22-Aug-09 17:35
BluesEnd22-Aug-09 17:35 
AnswerRe: How do I programmatically add data to a report - and how do I draw the report? Pin
Mycroft Holmes22-Aug-09 18:15
professionalMycroft Holmes22-Aug-09 18:15 
GeneralRe: How do I programmatically add data to a report - and how do I draw the report? Pin
BluesEnd23-Aug-09 3:09
BluesEnd23-Aug-09 3:09 
GeneralRe: How do I programmatically add data to a report - and how do I draw the report? Pin
Mycroft Holmes23-Aug-09 14:13
professionalMycroft Holmes23-Aug-09 14:13 
QuestionGet Picture if background is transparent Pin
Anubhava Dimri21-Aug-09 21:51
Anubhava Dimri21-Aug-09 21:51 
AnswerRe: Get Picture if background is transparent Pin
Eddy Vluggen22-Aug-09 2:17
professionalEddy Vluggen22-Aug-09 2:17 
GeneralRe: Get Picture if background is transparent Pin
Anubhava Dimri22-Aug-09 2:45
Anubhava Dimri22-Aug-09 2:45 
GeneralRe: Get Picture if background is transparent Pin
Eddy Vluggen22-Aug-09 3:22
professionalEddy Vluggen22-Aug-09 3:22 
GeneralRe: Get Picture if background is transparent Pin
Anubhava Dimri23-Aug-09 18:54
Anubhava Dimri23-Aug-09 18:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.