Click here to Skip to main content
15,917,059 members
Home / Discussions / C#
   

C#

 
GeneralRe: DataGridView customization Pin
Tony Pottier25-Mar-08 7:22
Tony Pottier25-Mar-08 7:22 
GeneralRe: DataGridView customization Pin
Xmen Real 25-Mar-08 15:28
professional Xmen Real 25-Mar-08 15:28 
Questionhow i can make remote backup server using C# Pin
saiftanoli25-Mar-08 5:51
saiftanoli25-Mar-08 5:51 
AnswerRe: how i can make remote backup server using C# Pin
led mike25-Mar-08 5:55
led mike25-Mar-08 5:55 
QuestionHow to add text in richtextbox from rtf file? Pin
Aravinthan25-Mar-08 5:51
Aravinthan25-Mar-08 5:51 
AnswerRe: How to add text in richtextbox from rtf file? Pin
led mike25-Mar-08 5:56
led mike25-Mar-08 5:56 
GeneralRe: How to add text in richtextbox from rtf file? Pin
Aravinthan25-Mar-08 6:30
Aravinthan25-Mar-08 6:30 
QuestionGDI+ Invalidate() artifacts Pin
Herbertmunch25-Mar-08 5:29
Herbertmunch25-Mar-08 5:29 
Hi all,

Could someone please explain to me why the following code doesnt work?


<code>
Rectangle r = new Rectangle(0, 0, 100, 100);
Pen p = Pens.Black;
private void Form1_Load(object sender, EventArgs e)
{

this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.UserPaint,true);

//a.AddLine(new Point(10, 10), new Point(100, 10));

}
protected override void OnMouseMove(MouseEventArgs e)
{
//Invalidate old location
Invalidate(r);
r.Location = e.Location;
//Invalidate new location
Invalidate(r);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);

//Clear clipping rect

e.Graphics.FillRectangle(Brushes.White, r);

//Draw invalidated region
e.Graphics.DrawRectangle(p, r); //Method will draw the right and bottom side out of clipping rect

}</code>

When i run it, the rectangles bottom and right hand side are drawn outside the clipping rectangle. I thought that if something was drawn outside the clipping rectangle, it would be discarded. However this doesnt seem to be the case here.

when i move the mouse, I move the rectangles location also. Before i change the location of the rect, i invalidate it, and then invalidate again once change has been made.

In the drawing routine i wipe the clipping rect with background colour, but for some reason artifacts ouside the clipping area remain.

The end result of the mouse move is an artifact trail, similar to a mouse trail and exactly like what happens, when you win at ms solitare.

It would appear that im not invalidating the right area, but i dont understand why!

I have done a fair bit of graphics programming before, and have never experienced any problem like this. If im invalidating the old bounds before changing them for the new bounds, it should be removing the old screen.


If i change the drawing code to make sure that the rectangle is drawn inside the clipping rect, the problem doesnt happen.
But I just cant understand why the problem occurs anyway. Surely invalidate should cause the overlapping line to be removed?

Here is the code that has been modified not to overdraw the clipping region:


<code>
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);

//Clear clipping rect

e.Graphics.FillRectangle(Brushes.White, r);
Rectangle r2 = r;
r2.Height -= 1;
r2.Width -= 1;
//Draw invalidated region
e.Graphics.DrawRectangle(p, r2); //Method will draw the right and bottom side out of clipping rect

}</code>

I would be most grateful to anyone that could point me in the right direction, or tell me if im doing something stupid.

Many thanks,
chris.

Thanks for your help!

<div class="ForumMod">modified on Tuesday, March 25, 2008 11:47 AM</div>
GeneralRe: GDI+ Invalidate() artifacts Pin
vineas25-Mar-08 7:04
vineas25-Mar-08 7:04 
GeneralRe: GDI+ Invalidate() artifacts Pin
Herbertmunch25-Mar-08 9:32
Herbertmunch25-Mar-08 9:32 
GeneralRe: GDI+ Invalidate() artifacts Pin
vineas25-Mar-08 11:49
vineas25-Mar-08 11:49 
GeneralRe: GDI+ Invalidate() artifacts Pin
Herbertmunch27-Mar-08 9:49
Herbertmunch27-Mar-08 9:49 
Generaldatatable Pin
arkiboys25-Mar-08 5:12
arkiboys25-Mar-08 5:12 
GeneralRe: datatable Pin
Xmen Real 25-Mar-08 5:34
professional Xmen Real 25-Mar-08 5:34 
GeneralRe: datatable [modified] Pin
arkiboys25-Mar-08 5:46
arkiboys25-Mar-08 5:46 
GeneralListView Single Range Selection Pin
Echilon25-Mar-08 4:27
Echilon25-Mar-08 4:27 
GeneralRe: ListView Single Range Selection Pin
Xmen Real 25-Mar-08 5:36
professional Xmen Real 25-Mar-08 5:36 
QuestionHow can i found which process access my file? Pin
Ambarish Jana25-Mar-08 3:58
Ambarish Jana25-Mar-08 3:58 
AnswerRe: How can i found which process access my file? Pin
Rob Philpott25-Mar-08 5:10
Rob Philpott25-Mar-08 5:10 
GeneralRe: How can i found which process access my file? Pin
Giorgi Dalakishvili25-Mar-08 7:53
mentorGiorgi Dalakishvili25-Mar-08 7:53 
Generalcopy listbox items Pin
NewToAspDotNet25-Mar-08 3:41
NewToAspDotNet25-Mar-08 3:41 
GeneralRe: copy listbox items Pin
Gareth H25-Mar-08 4:16
Gareth H25-Mar-08 4:16 
GeneralRe: copy listbox items Pin
partialdata18-Aug-09 17:31
partialdata18-Aug-09 17:31 
Generalenum problem in C# Pin
salon25-Mar-08 3:13
salon25-Mar-08 3:13 
GeneralRe: enum problem in C# Pin
Russell Jones25-Mar-08 3:48
Russell Jones25-Mar-08 3:48 

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.