473,703 Members | 2,543 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to paint on top of a forms main menu?

Hi,

I am trying to draw on top of the main menu area of a form (this is just a
test
at the moment). I'm handling the forms paint event and using the following
code:

private void Form1_Paint(obj ect sender, System.Windows. Forms.PaintEven tArgs
e)
{
try
{
using (Graphics g = Graphics.FromHw nd(mainMenu1.Ha ndle))
{
RectangleF testBox = new RectangleF(g.Cl ipBounds.Width - 50,
g.ClipBounds.Y, 50, g.ClipBounds.He ight);
using (StringFormat sf = new StringFormat())
{
sf.Alignment = StringAlignment .Center;
sf.LineAlignmen t = StringAlignment .Center;
g.FillRectangle (Brushes.Yellow , testBox);
g.DrawString("T EST", this.Font, Brushes.Black, testBox, sf);
}
}
base.OnPaint(e) ;
}
catch (Exception ex)
{
MessageBox.Show (ex.ToString()) ;
}
}

....however I get an OutOfMemoryExce ption error on the line above that starts
using (Graphics g = Graphics.FromHw nd(...

Anybody have any ideas about how I might achieve this?
All ideas welcome, although I don't want to have to use the Win API if I can
help it.

Regards,
Peter
Feb 1 '06 #1
2 1837
Peter,

You can't do what you are doing, trying to get the Graphics instance
from the handle of the menu. The menu handle is not a window handle, but
something else completely.

What you have to do is get the handle of the window the menu is attached
to, and then paint that. This is not the recommended way, however.

Do you have to paint over the menu, or can you just get by painting the
menu items? If it is the latter, then just set the OwnerDraw property to
true and handle the DrawItem event.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Peter Row" <ge******@spamm ers.com> wrote in message
news:Ox******** *****@TK2MSFTNG P14.phx.gbl...
Hi,

I am trying to draw on top of the main menu area of a form (this is just a
test
at the moment). I'm handling the forms paint event and using the following
code:

private void Form1_Paint(obj ect sender,
System.Windows. Forms.PaintEven tArgs e)
{
try
{
using (Graphics g = Graphics.FromHw nd(mainMenu1.Ha ndle))
{
RectangleF testBox = new RectangleF(g.Cl ipBounds.Width - 50,
g.ClipBounds.Y, 50, g.ClipBounds.He ight);
using (StringFormat sf = new StringFormat())
{
sf.Alignment = StringAlignment .Center;
sf.LineAlignmen t = StringAlignment .Center;
g.FillRectangle (Brushes.Yellow , testBox);
g.DrawString("T EST", this.Font, Brushes.Black, testBox, sf);
}
}
base.OnPaint(e) ;
}
catch (Exception ex)
{
MessageBox.Show (ex.ToString()) ;
}
}

...however I get an OutOfMemoryExce ption error on the line above that
starts
using (Graphics g = Graphics.FromHw nd(...

Anybody have any ideas about how I might achieve this?
All ideas welcome, although I don't want to have to use the Win API if I
can
help it.

Regards,
Peter

Feb 1 '06 #2
Why don't you want to use API? AFAIK it's the only way to do it, and you'll
find an example using API on my site:
http://www.dotnetrix.co.uk/menus.html --> Custom MenuBar color

The example uses a SolidBrush but you can easily replace that with a
TextureBrush.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Peter Row" <ge******@spamm ers.com> wrote in message
news:Ox******** *****@TK2MSFTNG P14.phx.gbl...
Hi,

I am trying to draw on top of the main menu area of a form (this is just a
test
at the moment). I'm handling the forms paint event and using the following
code:

private void Form1_Paint(obj ect sender,
System.Windows. Forms.PaintEven tArgs e)
{
try
{
using (Graphics g = Graphics.FromHw nd(mainMenu1.Ha ndle))
{
RectangleF testBox = new RectangleF(g.Cl ipBounds.Width - 50,
g.ClipBounds.Y, 50, g.ClipBounds.He ight);
using (StringFormat sf = new StringFormat())
{
sf.Alignment = StringAlignment .Center;
sf.LineAlignmen t = StringAlignment .Center;
g.FillRectangle (Brushes.Yellow , testBox);
g.DrawString("T EST", this.Font, Brushes.Black, testBox, sf);
}
}
base.OnPaint(e) ;
}
catch (Exception ex)
{
MessageBox.Show (ex.ToString()) ;
}
}

...however I get an OutOfMemoryExce ption error on the line above that
starts
using (Graphics g = Graphics.FromHw nd(...

Anybody have any ideas about how I might achieve this?
All ideas welcome, although I don't want to have to use the Win API if I
can
help it.

Regards,
Peter

Feb 2 '06 #3

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

Similar topics

3
2286
by: Joshua Russell | last post by:
Hi, Both the methods below open up a windows form called MasterForm. However, one works better than the other. Method 1 opens the form correctly but I don't have any reference to the instance of master form. Method 2 opens the form but when I right click on the Notify Icon I don't get the context menu that I should be seeing. I can interact with the main form window but I cannot interact with the NotifyIcon. Method 2 gives a object reference...
0
1903
by: Duncan Mole | last post by:
Hi, I have created a control which draws a title bar and provides a drop down menu for a Smart Device Application. It seemed to work fine until I came to add an event handler to act on Paint messages in the form which has drawn the control. Evidently, the control is consuming all of these messages. How can I pass them back/on? I have a reference to the owner form but calling Refresh() via this reference isn't helping. Help! Do I need to...
2
4910
by: Serge Klokov | last post by:
Hi! 1. Please, help with example "paint on form by mouse" 2. Below is my example, but it clear the line after each Refresh()... how to fix? 3. How to draw the line in Mouse_Move event? private Boolean isCanPaint = false; private MouseEventArgs MouseEvent1;
2
2682
by: VSNT | last post by:
Is there a way to paint the backcolor of a main menu. I can paint the menu ites from the size and paint events but there doesnot appear to be an accessable paint method for the actual MainMenu control. The Idea is to not have a standard windows MainMenu (AKA: Gray in in most cases) but something that matches and flows with the rest of the GUI. Any ideas much apreciated. Thanks, Allen
3
1979
by: Mike Cooper | last post by:
I have been staring at the above error for over a week now! I have a an inherited data class looking like thus: Public Class DataGridBoolColumnInherit Inherits System.Windows.Forms.DataGridBoolColumn Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal As CurrencyManager, ByVal rowNum As Integer, ByVal backBrush As Brush, ByVal foreBrush As Brush, ByVal alignToRight As Boolean)
6
1980
by: Jrsmith | last post by:
I am developing a mdi application that will act as a front end to a database. I am finding that when i show any of the mdi child forms in my application it is noticeable that the form is shown first with the areas where the controls will be displayed cut out and what ever is top most before the form is shown is momentarity seen through these areas. This is also noticed if the user changes focus to say internet explorer and then back to...
2
4899
by: Mario | last post by:
Hi, I am trying to create an application with multiple windows forms. The problem that I have is that after creating the window forms, I do not know how to open formN after closing Main form. Each form is in its own class. What I want to do is the following: 1. Click a button on Main menu. 2. Close main menu ( I would use hide if possible) 3. Open form2
7
2517
by: Gary Brown | last post by:
Hi, I have a computation intensive application that tries to update the display quite often. After a few seconds the window stops updating and the window goes blank. A breakpoint in the Paint event doesn't trigger. Further, if another window obscures the display while it is still working the display is blank after it is uncovered. Also, when the window is blank, the program does not
9
2357
by: raylopez99 | last post by:
Just an observation: pens for drawing lines in Win Forms are tricky when assignment is inside the paint handler. inside of the Paint handler, but not inside a "using" brace (that is, outside of "using { Pen mypen = new Pen(Color.Black, 1)) {}), which I think makes a difference: I find the following assignment does not work: //myPenTest instantiated in the normal constructor, as was baseline,
0
8750
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, 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...
0
8662
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,...
0
9246
Oralloy
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...
0
9112
jinu1996
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...
1
6585
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 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...
0
4425
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...
0
4680
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2440
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2058
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.