 |
|
 |
Yes you're right. But i don't think that this is the best solution, infact in that way works because the base control uses directly the field of the context menu, and not the property, but you can't know if in the feature it will do so (even if it would be illogical not doing that). The real solution would be renaming also the property, and not only using a different field, or another (worse) solution would be overriding the (right) click event handler.
Using the property you need also to change the OnMouseDown method override, from:
if (_AlwaysDropDown || MouseInSplit())
{
if (Enabled)
{
...
To:
if (_AlwaysDropDown || MouseInSplit())
{
if (Enabled && mevent.Button == MouseButtons.Left)
{
...
Thanks anyway for the report.
|
|
|
|
 |
|
 |
I find your SplitButton very usefull.
One thing though. When I disable the button, the background image stays enabled.
Could you tell me how to fix that?
Thanks,
Golan Bar-Nov.
|
|
|
|
 |
|
 |
You have to select the disabled image in the DisabledImage property of the SplitButton (under "Split Button Images" category), after setting the ImageList property to your ImageList, it's not automatically selected/grayed. I think I'm going to update this article/control in the near future, but I'm too busy at this time.
|
|
|
|
 |
|
 |
Thank you for your quick reply.
The disabled image under the "Split Button Images" refers to the arrow image on a disabled mode. There is another image in the button's base class called BackgroundImage which stays enabled when the control is disabled.
|
|
|
|
 |
|
 |
The control doesn't check the background image, and nor use that property, so is not a control fault if it remains enabled. So if you want to disable it you must do by yourself, and that shouldn't be difficult. Simply create a grayed-scale of your image, this routine should work:
public static Image CreateDisabledImage(Image normalImage)
{
ImageAttributes attributes1 = new ImageAttributes();
attributes1.ClearColorKey();
attributes1.SetColorMatrix(ToolStripRenderer.DisabledImageColorMatrix);
Size size1 = normalImage.Size;
Bitmap bitmap1 = new Bitmap(size1.Width, size1.Height);
Graphics graphics1 = Graphics.FromImage(bitmap1);
graphics1.DrawImage(normalImage, new Rectangle(0, 0, size1.Width, size1.Height), 0, 0, size1.Width, size1.Height, GraphicsUnit.Pixel, attributes1);
graphics1.Dispose();
return bitmap1;
}
|
|
|
|
 |
|
 |
Sorry, this is the complete code to disable an image (example program class):
static class Program
{
static ColorMatrix DisabledImageColorMatrix;
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
float[][] singleArrayArray1 = new float[5][];
singleArrayArray1[0] = new float[] { 0.2125f, 0.2125f, 0.2125f, 0f, 0f };
singleArrayArray1[1] = new float[] { 0.2577f, 0.2577f, 0.2577f, 0f, 0f };
singleArrayArray1[2] = new float[] { 0.0361f, 0.0361f, 0.0361f, 0f, 0f };
float[] singleArray1 = new float[5];
singleArray1[3] = 1f;
singleArrayArray1[3] = singleArray1;
singleArrayArray1[4] = new float[] { 0.38f, 0.38f, 0.38f, 0f, 1f };
float[][] singleArrayArray2 = new float[5][];
float[] singleArray2 = new float[5];
singleArray2[0] = 1f;
singleArrayArray2[0] = singleArray2;
float[] singleArray3 = new float[5];
singleArray3[1] = 1f;
singleArrayArray2[1] = singleArray3;
float[] singleArray4 = new float[5];
singleArray4[2] = 1f;
singleArrayArray2[2] = singleArray4;
float[] singleArray5 = new float[5];
singleArray5[3] = 0.7f;
singleArrayArray2[3] = singleArray5;
singleArrayArray2[4] = new float[5];
DisabledImageColorMatrix = MultiplyColorMatrix(singleArrayArray2, singleArrayArray1);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
public static Image CreateDisabledImage(Image normalImage)
{
ImageAttributes attributes1 = new ImageAttributes();
attributes1.ClearColorKey();
attributes1.SetColorMatrix(Program.DisabledImageColorMatrix);
Size size1 = normalImage.Size;
Bitmap bitmap1 = new Bitmap(size1.Width, size1.Height);
Graphics graphics1 = Graphics.FromImage(bitmap1);
graphics1.DrawImage(normalImage, new Rectangle(0, 0, size1.Width, size1.Height), 0, 0, size1.Width, size1.Height, GraphicsUnit.Pixel, attributes1);
graphics1.Dispose();
return bitmap1;
}
static ColorMatrix MultiplyColorMatrix(float[][] matrix1, float[][] matrix2)
{
int num1 = 5;
float[][] singleArrayArray1 = new float[num1][];
for (int num2 = 0; num2 < num1; num2++)
{
singleArrayArray1[num2] = new float[num1];
}
float[] singleArray1 = new float[num1];
for (int num3 = 0; num3 < num1; num3++)
{
for (int num4 = 0; num4 < num1; num4++)
{
singleArray1[num4] = matrix1[num4][num3];
}
for (int num5 = 0; num5 < num1; num5++)
{
float[] singleArray2 = matrix2[num5];
float single1 = 0f;
for (int num6 = 0; num6 < num1; num6++)
{
single1 += singleArray2[num6] * singleArray1[num6];
}
singleArrayArray1[num5][num3] = single1;
}
}
return new ColorMatrix(singleArrayArray1);
}
}
|
|
|
|
 |
|
 |
Thank you Gladstone. That was just what i was looking for.
|
|
|
|
 |
|
 |
In .Net 2.0 you can embedd a toolbar in a form completely invisibly. This way you can add the split buttons etc without need for coding...
Have a nice life!!
|
|
|
|
 |
|
 |
I don't agree, the "SplitButton" from a ToolBar will not look like a CommandButton (colors etc).
But if you have found a solution for this, please let us know.
|
|
|
|
 |
|
 |
It has the same colour as the dialog itself. You should try it...
Have a nice life!!
|
|
|
|
 |
|
 |
I've tried, but had some troubles. It looks like a button when the button get focus, but not else.
How did you get the ToolStrip to be invisible?
What setting did you set in the ToolsStrip and on the ToolStipDownButton?
|
|
|
|
 |
|
 |
why would you want to waste the resources of embedding a toolbar into your screen if you DO NOT need one?
|
|
|
|
 |
|
 |
What I don't like about using ToolStripButton when I need the drop-down-like button is that it don't look like a conventional button. I once used ToolStripButton in a row of simple command buttons and this didn't look too elegant: the appearance of ToolStripButton differs distinctively from that of simple command buttons.
Back in 2005 I used the same approach as you did here to simulate drop-down button in .NET 1.1: conventional button with the image of an arrow facing down. The problem with this approach is that you cannot have another image on the button, besides the down-facing arrow, while ToolStripButton can.
|
|
|
|
 |
|
 |
hi all,
the subject is the question...
thks
|
|
|
|
 |
|
|
 |
|
 |
Hi,
Nice control, and one that I needed.
I would like to use the control in several forms in VB.NET as well as in C#.
I testet it in VB.NET (in VS 2005) by compiling it into a dll, it seemed to work well.
What I would suggest is that it's made into a Windows Control, and that the Imagelist is hidden inside the control (it may be overridden if somebody wants that).
Thanks,
Lars
|
|
|
|
 |
|
 |
Infact the concept behind the possibility to select what image to use inside the ImageList with the dropdown design-time selector for the split button statuses, is that i wanted the user could change images for the non-button part of the split button, the ones i put inside the demo were only for demo and for ready-to-use purposes.
|
|
|
|
 |
|
 |
I agree, its a nice feature.
But for my suits I modified the code for reuse in both VB.NT and in C#.
What I did:
- Compiled into a Class Library DLL
- Filled in some predefined properties in the constructor, so the DropDown part will show
when I insert the splitbutton in a form.
( ImageList "SplitButtonImages" has been added to the "control" )
- Can be used in VB.NET as well in C#.
Code:
public SplitButton()
{
InitializeComponent();
// LARS: Fill in some predefined properties, so the DropDown part will show
// ImageList "SplitButtonImages" has been added to the "control"
CalculateSplitRect = true;
ImageList = SplitButtonImages;
ImageAlign = ContentAlignment.MiddleRight;
NormalImage = "SplitButtonImage.gif";
DisabledImage = "SplitButtonDisabledImage.gif";
HoverImage = "SplitButtonHoverImage.gif";
ClickedImage = "SplitButtonClickedImage.gif";
FocusedImage = null;
FillSplitHeight = true;
TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
TextImageRelation = System.Windows.Forms.TextImageRelation.TextBeforeImage;
}
What I miss and couldn't figure out was how to resize the image when the button was resized.
And may be it should have been put into Windows Control library.
Thanks,
Lars
|
|
|
|
 |
|
|
 |