menuStrip1.Renderer.DrawSeparator problem(error)
Hey,
I am using
menuStrip1.Renderer.DrawSeparator to use my own image for the seperator for the menu strip in my program. I tryed doing this:
menuStrip1.Renderer.DrawSeparator = SurfScape1.Properties.
Resources.seperator;But i got an error saying:Cannot assign to 'DrawSeparator' because it is a 'method group'
How do I fix this?
Thanks :)
Hi,
if you'd like to draw your own separator, either
a] make your own Renderer by inheriting from ToolStripRenderer and overriding wanted methods. You can later assign your Renderer to the menu strip:
menuStrip1.Renderer =
new MyRenderer();b] subscribe to the RenderSeparator event:
menuStrip1.Renderer.RenderSeparator +=
new ToolStripSeparatorRenderEventHandler(Renderer_RenderSeparator);void Renderer_RenderSeparator(object sender, ToolStripSeparatorRenderEventArgs e)
{
e.Graphics.DrawImage(SurfScape1.Properties.Resources.seperator, new Point(0, 0));
}[Assuming SurfScape1.Properties.Resources.seperator is a bitmap...]
You're getting the error because you're trying to assign a value to a method [DrawSeparator is a method].
Andrej
Hey,
there is a problem...I used the 2nd way to do it... But it keeps the old divider and it only makes my divider it's original size, 1x2...Do I have to tell it to streach it?
And it it a .png
Thanks :)
Hi,
you can draw whatever you like on the Graphics, even clear it:
e.Graphics.Clear(
Color.White);To strech the image, you can use something like:
e.Graphics.DrawImage(
SurfScape1.Properties.Resources.seperator, new Rectangle(0,0, e.Item.Bounds.Width, e.Item.Bounds.Height));Andrej
ok, well, I tryed it and...I just took out the graphics clear part, but the seperator... ... ... It steached, but it became a 4 pixel hight and a gradient from it's color to the drop down list's background color(white)...actualy it starts getting it's own alpha, becuase the old default seperator you can see under it where it starts to get white, so it is getting transparent...
How do I fix this?
Thanks :)
You can get rid of the old separator line by clearing the graphics. How do you want it to draw grapics? Bigger?
You can also make your own separator toolitem and add it to your menus, if you want it to look/behave much different than the default one...
Andrej
Well,
the image is fadding....as it gets steached, so thats what I am trying to fix...
But the image hight is streached it's hight also...
But what you are saying is I can amke a menuitem that looks and act like a seperator?(just do this __?)
Thanks :)
progames25 wrote: |
| the image is fadding....as it gets steached... |
|
Would it be possible for you to fix the image to the transparency? If this transparency is what you like the image to look like, clear the graphics with background color prior to drawing the image.
progames25 wrote: |
| But the image hight is streached it's hight also... |
|
Yes, using the above code, the image is streched so it occupies all available space that's there for separator to draw onto. How would you like your image to be drawn? What size is it?
progames25 wrote: |
| But what you are saying is I can amke a menuitem that looks and act like a seperator?(just do this __?) |
|
You can make your own menu item that looks exactly as you want (it's like your would make your own user control and put it in the place of the separator...)
Andrej
ok...
the image size is 1 width 2 hight, I want the hight to stay 2 butt he width to streach...
I am alos making one witht he same image for the toolstrip border, it works just fine but it also starts to fade to transparencey...but transparencey is not what I want, so thats the problem...with that part...
Since your image is really small, would it work for you if you'd draw a line instead of a bitmap? Like this:
Rectangle rect = e.Item.ContentRectangle; // Experiment with rectangle size and position here
e.Graphics.FillRectangle(Brushes.Violet, rect);Andrej
Ok, it works, thanks, I guess I will do a similare thing with the border...
And one more question and I will be good, Is ther a way to clear JUST the old border on a toolstrip? becuase I have a 160x2 image for the border of the toolstrip, and at the end , about the last 4 pixels start to go transparent and you can see the old border... but I like the way JUST the last 4 pixels go transparent...but the old border you can see, and if I was to do a full clear then it would mess up the skin, becuase I ahve added a background image to the toolstrip and there are buttons thta will all disapear...so like Is aid before, is there a way to JUST clear the OLD border of the tool strip?
Thanks :)
Well...I guess that dose not matter, but what dose is that I can't change the border of the menustrip...only the toolstrip...So is there any way to do the same thing I did for the border of the toolstrip for the menustrip? or at least delete the border of the menustrip?
Thanks :)
Anyone?
I cant get it to do both borders...SO I tryed to have it remove the menustrip border...but Ic ant get it...I tryed making it have a custom border for toolstrip AND menustrip but I cant get it to do both...It will only let me do one or the other...
Thanks :)