Hi there. I have written a small procedure to draw various shapes on
things. A bit of it is shown below.
Private Sub drawShape(ByVal shapeType As Integer, ByRef g As Graphics)
Select Case shapeType
Case 1 : g.DrawRectangle (New Pen(Color.Black ), 0, 0, 50, 10)
Case 2 'draw a circle
Case 3 'draw a triangle
Case 4 'draw other shape
Case 5 'draw other shape
Case 6 'draw other shape
Case Else 'etc. draw other shapes
End Select
End Sub
If on Form1, I override the OnPaint method with
Protected Overrides Sub OnPaint(ByVal e As
System.Windows. Forms.PaintEven tArgs)
MyBase.OnPaint( e)
drawShape(1, e.Graphics)
End Sub
it paints my rectangle as I would expect drawing it on Form1 at 0,0
with width 50 and height 10.
I have lots of other controls on the form, such as buttons, labels,
groupboxes etc. My question is how do I get 'g' (a valid Graphics
instance) for the buttons, labels, groupboxes and other things.
The obvious thing I tried below doesn't work (I see no rectangle on
the GroupBox, called GroupBox1) but still see the rectangle on the
form. I want to see both.
Protected Overrides Sub OnPaint(ByVal e As
System.Windows. Forms.PaintEven tArgs)
MyBase.OnPaint( e)
drawShape(1, e.Graphics)
drawShape(1, Me.GroupBox1.Cr eategraphics())
End Sub
Thank you in advance for all your help and sorry to post more of these
verbose and tricky questions.
Colin 3 10326
Colin - you have come a long way judging by the type of questions you are
now asking.
I'm not going to answer your question directly but provide you with some
information that should enable you to work out the answer to your question
yourself.
If Panel1 is a Panel on your form, TabControl1 is a TabControl on your form,
and Button1 is a Button on your form, when OnPaint is executed
Protected Overrides Sub OnPaint(ByVal e As
System.Windows. Forms.PaintEven tArgs)
MyBase.OnPaint( e)
Dim g As Graphics = Panel1.CreateGr aphics()
drawShape(1, g)
g.Dispose()
g=TabControl1.C reateGraphics()
drawShape(1,g)
g.Dispose()
g=Button1.Creat egraphics()
drawShape(1,g)
g.Dispose()
End Sub
you will see your blue rectangle on both Panel1 and TabControl1, but not
Button1. Ask yourself why the rectangle draws on some form objects but not
others - what is different about them and how would/could you change the
observed behaviour.
Regards
Hexathioorthoox alate
PS: Here's an excerpt from the on-line (VB.NET 2003) docs for
CreateGraphics. Quote: "The returned Graphics object must be disposed
through a call to its Dispose method when it is no longer needed.". Your use
of drawShape(1, Me.GroupBox1.Cr eategraphics()) doesn't and can't dispose of
the graphics object as written.
"Colin McGuire" <co***********@ lycos.co.uk> wrote in message
news:ab******** *************** ***@posting.goo gle.com... Hi there. I have written a small procedure to draw various shapes on things. A bit of it is shown below.
Private Sub drawShape(ByVal shapeType As Integer, ByRef g As Graphics) Select Case shapeType Case 1 : g.DrawRectangle (New Pen(Color.Black ), 0, 0, 50, 10) Case 2 'draw a circle Case 3 'draw a triangle Case 4 'draw other shape Case 5 'draw other shape Case 6 'draw other shape Case Else 'etc. draw other shapes End Select End Sub
If on Form1, I override the OnPaint method with
Protected Overrides Sub OnPaint(ByVal e As System.Windows. Forms.PaintEven tArgs) MyBase.OnPaint( e) drawShape(1, e.Graphics) End Sub
it paints my rectangle as I would expect drawing it on Form1 at 0,0 with width 50 and height 10.
I have lots of other controls on the form, such as buttons, labels, groupboxes etc. My question is how do I get 'g' (a valid Graphics instance) for the buttons, labels, groupboxes and other things.
The obvious thing I tried below doesn't work (I see no rectangle on the GroupBox, called GroupBox1) but still see the rectangle on the form. I want to see both.
Protected Overrides Sub OnPaint(ByVal e As System.Windows. Forms.PaintEven tArgs) MyBase.OnPaint( e) drawShape(1, e.Graphics) drawShape(1, Me.GroupBox1.Cr eategraphics()) End Sub
Thank you in advance for all your help and sorry to post more of these verbose and tricky questions. Colin
Hex - thanks for your help.
The Panel etc are .Net controls, and the Button is a Windows control?
But I still want to draw on the Button too. How?
Thank you
Colin.
Hex isnt online today. Could someone else help me out here please.
I can see that rectangles are only drawn on objects that are not
Windows controls (such as buttons and textboxes).
How can I tell as a general rule whether the object is drawn by the
framework and not by Windows? Currently a "GroupBox" is drawn by the
framework but what if Microsoft modify Windows so that it is drawn
there - then my code won't work. So what I think I want it a
subroutine to pass a object (like a button, or a panel, or a
groupbox), and the subroutine print out whether the object is drawn by
Windows or the framework (and therefore whether my blue rectangle,
code below, will be drawn).
Thank you
Colin
"Hexathioorthoo xalate" <ru***@spamerem ove.clara.co.uk > wrote in message news:<10******* *********@damia .uk.clara.net>. .. Colin - you have come a long way judging by the type of questions you are now asking.
I'm not going to answer your question directly but provide you with some information that should enable you to work out the answer to your question yourself.
If Panel1 is a Panel on your form, TabControl1 is a TabControl on your form, and Button1 is a Button on your form, when OnPaint is executed
Protected Overrides Sub OnPaint(ByVal e As System.Windows. Forms.PaintEven tArgs) MyBase.OnPaint( e) Dim g As Graphics = Panel1.CreateGr aphics() drawShape(1, g) g.Dispose() g=TabControl1.C reateGraphics() drawShape(1,g) g.Dispose() g=Button1.Creat egraphics() drawShape(1,g) g.Dispose() End Sub
you will see your blue rectangle on both Panel1 and TabControl1, but not Button1. Ask yourself why the rectangle draws on some form objects but not others - what is different about them and how would/could you change the observed behaviour.
Regards Hexathioorthoox alate
PS: Here's an excerpt from the on-line (VB.NET 2003) docs for CreateGraphics. Quote: "The returned Graphics object must be disposed through a call to its Dispose method when it is no longer needed.". Your use of drawShape(1, Me.GroupBox1.Cr eategraphics()) doesn't and can't dispose of the graphics object as written.
"Colin McGuire" <co***********@ lycos.co.uk> wrote in message news:ab******** *************** ***@posting.goo gle.com... Hi there. I have written a small procedure to draw various shapes on things. A bit of it is shown below.
Private Sub drawShape(ByVal shapeType As Integer, ByRef g As Graphics) Select Case shapeType Case 1 : g.DrawRectangle (New Pen(Color.Black ), 0, 0, 50, 10) Case 2 'draw a circle Case 3 'draw a triangle Case 4 'draw other shape Case 5 'draw other shape Case 6 'draw other shape Case Else 'etc. draw other shapes End Select End Sub
If on Form1, I override the OnPaint method with
Protected Overrides Sub OnPaint(ByVal e As System.Windows. Forms.PaintEven tArgs) MyBase.OnPaint( e) drawShape(1, e.Graphics) End Sub
it paints my rectangle as I would expect drawing it on Form1 at 0,0 with width 50 and height 10.
I have lots of other controls on the form, such as buttons, labels, groupboxes etc. My question is how do I get 'g' (a valid Graphics instance) for the buttons, labels, groupboxes and other things.
The obvious thing I tried below doesn't work (I see no rectangle on the GroupBox, called GroupBox1) but still see the rectangle on the form. I want to see both.
Protected Overrides Sub OnPaint(ByVal e As System.Windows. Forms.PaintEven tArgs) MyBase.OnPaint( e) drawShape(1, e.Graphics) drawShape(1, Me.GroupBox1.Cr eategraphics()) End Sub
Thank you in advance for all your help and sorry to post more of these verbose and tricky questions. Colin This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Joe Kelsey |
last post by:
When you use addEventListener (or addEvent in IE) to call an object
method, does it call it with the correct this parameter?
The ECMAScript reference has a lot to say about the caller using
Function.prototype.call or Function.prototype.apply and passing the
correct this pointer for the context, but how does addEventListener
determine the correct this pointer. Or does it just punt and pass the
global context, thus making it impossible to...
|
by: William Apple |
last post by:
Despite the fact this deals with webservices I believe it is a VB question.
I am working on a test application that passes data to a webservice.
The webservices takes a variable type that is defined below:
Public Class Variable
Inherits MarshalByRefObject
'<remarks/>
Public strVariableName As String
|
by: Ram |
last post by:
Hi All,
I am using Object Data Source to bind data in the gridview. I have
set the property AllowSorting=true. While running the application, I
could sort the data only in ascending order. Is there any way to
achieve two way sorting in gridview ie. both ascending and descending
on successive clicks ?.
Please give me a suggestion to solve this issue. Thanks in advance.
|
by: burningodzilla |
last post by:
Hi all - I'm preparing to dive in to more complex application
development using javascript, and among other things, I'm having a hard
time wrapping my head around an issues regarding "inheritance" using
the prototype property. I realize there are no classes in JS, that code
therefore lives in objects instead of class definitions, and that
"inheritance" must be achieved prototypically and not classically.
That said, on with the code. Say I...
|
by: sajithamol |
last post by:
I have a dll of a VB application which performs image manipulations. I want to build this dll file into a .cab file to embed this in the Object tag in client side. Also how to generate the classid for the .cab file which is a required parameter for using Object tag.
| |
by: Veloz |
last post by:
Hiya
My question is whether or not you should associated related objects in
your software using a scheme of id's and lookups, or wether objects
should actually hold actual object references to objects they are
associated with.
For example, lets say you are modelling studen ratings of teachers.
Let's say your applications needs to analyze these ratings for
teachers and is provided a data file. In this data file the teachers
all have...
|
by: busiswa |
last post by:
Hi All,
I am just new in PHP, i am asked to draw a combobox using the draw() method. Can someone help me on how to go about that.
Thank you,
Busi
|
by: Duggi |
last post by:
I used to wonder why MS implemented C# to accept the following code
using (Font f = new Font())
{
// some code here.
}
While the same can be achieved through
{
|
by: Duggi |
last post by:
I used to wonder why MS implemented C# to accept the following code
using (Font f = new Font())
{
// some code here.
}
While the same can be achieved through
{
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| | |