473,511 Members | 15,818 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1635
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
9031
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
3619
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
4038
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
1356
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
17402
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
8949
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
9857
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
279
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
12853
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
7252
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5676
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5077
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.