473,324 Members | 2,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

System.Drawing and GDI+ Question - Please help

I have a winforms control that draws a rectangle for a boarder and positions
some graphical elements around the control to create the boarder effect I
desired. In the control I have overriden the onpaint event and added the
code to draw my rectangle and position my graphic items:

Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)

e.Graphics.Clear(Color.FromArgb(255, 255, 255))

MyBase.OnPaint(e)

Dim g As Graphics = pb1.CreateGraphics

pb1.CreateGraphics.Clear(Color.FromArgb(255, 255, 255))

Dim myPen As System.Drawing.Pen = New System.Drawing.Pen(Color.FromArgb(187,
191, 115))

g.DrawRectangle(myPen, New Rectangle(0, 0, pb1.Width - 1, pb1.Height - 1))

pb1.Width = (Me.Width - 34)

pb1.Height = (Me.Height - 29)

tr.Left = (Me.Width - 32)

br.Left = (Me.Width - 32)

br.Top = (Me.Height - 24)

bl.Top = (Me.Height - 24)

End Sub

Also I have added this line to the Public sub new call of the control:

SetStyle(ControlStyles.ResizeRedraw, True)

As you can see the rectangle is being drawn on a panel control called "pb1".

When I drag this control onto a Windows form in Visual Studio the rectangle
is drawn and behaves as it should when resized etc. However if I switch to
antother tab and switch back the rectangle disapears, this is also the case
when the solution is compiled the form initializes with no rectangle. Can
somebody please help me or point me in the right direction.
Jul 21 '05 #1
2 1617
I had same problem: redrawing. There are two way
1) draw picture again (too slow)
2) draw picture to memory bitmap and then copy it to graphis object (here in your code pb1). You can zoom, resize, bend ,what ever... before you show that picture. Fast!
Here more:
http://www.informit.com/content/inde...CF5179E3CBF%7D

Juha V
Jul 21 '05 #2
Thanks, interesting.

Firstly I found that my problem was I was doing more than just drawing in
the overrides onpaint event and that was causing my problem, so I removed
anything that wasn't drawing in that event.

Secondly I was also drawing the rectangle to a panel control and this was
known to cause issues, so I created a new control to draw the rectangle and
I placed this on my control that had the rest of the graphical elements.

It works sweet. This site is very useful http://bobpowell.net/faqmain.htm

Thanks
"Juha Virtanen" <ju***********@elisa.fi> wrote in message
news:0B**********************************@microsof t.com...
I had same problem: redrawing. There are two way
1) draw picture again (too slow)
2) draw picture to memory bitmap and then copy it to graphis object (here in your code pb1). You can zoom, resize, bend ,what ever... before you show
that picture. Fast! Here more:
http://www.informit.com/content/inde...CF5179E3CBF%7D
Juha V

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Buddy | last post by:
Hello, How can I use the 'System' or 'FixedSys' font in my .NET application using controls (TextBox, Button and ListView)? Thanks,
1
by: DBC User | last post by:
Hi Sharpies, This is a very basic question. I am using .Net IDE 2003 and System.Drawing.dll (1.1.4322). I wrote a simple program like this (ommitting the commons) using System.Drawing; .....
6
by: James dean | last post by:
I have heard that the video drivers in GDI+ are a big performance issue. But is this only an issue with something like Games Programming i think...is this wrong?. What about a drawing application...
9
by: Oddball | last post by:
Firstly I'd like to say hello. This is my first post having ghosted for some time - I know, I'm a bad man. I'm pretty sure this following post hasn't been adressed on the forum, I may be wrong -...
7
by: Randy Vande Hei | last post by:
Does anyone know how to change the the GDI+ coordinate system like you used to be able to do in VB6 with the picturebox.scale method. The picturebox.scale method took an x,y point defining the...
2
by: User | last post by:
Hi, What is the best way to release all resources holded by the Timer (myTimer from class System.Timers.Timer)? Is it: 1- myTimer.dispose 2- myTimer.enabled = false 3- myTimer.close
5
by: Michael C# | last post by:
Hi all, I set up a System.Timers.Time in my app. The code basically just updates the screen, but since the processing performed is so CPU-intensive, I wanted to make sure it gets updated...
2
by: padawan | last post by:
I have a winforms control that draws a rectangle for a boarder and positions some graphical elements around the control to create the boarder effect I desired. In the control I have overriden the...
5
by: Macias | last post by:
Hi, Please help me, how I can make a line drawing on PictureBox similar to MS paint. I thinking about this: click and hold button, move mouse and relase button. I'm trying useing this...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.