フォームにツールストリップを追加しました。このツールストリップでは、ツールストリップボタンを追加することにより、いくつかのボタンがありました。これらのボタンのデフォルトのサイズは22、20ですが、ボタンのサイズを25、50に変更したいと思います。サイズプロパティを変更してデザイナーで変更を加えましたが、フォームに反映されません。ツールストリップの高さを変更しても、変更されません。それで何か助けはありますか?
ToolStripButtonのAutoSize
プロパティをfalse
に変更すると、ボタンの幅を変更できるようになります。
ToolStripのAutoSize
プロパティをfalse
に変更すると、その高さを変更でき、ToolStripButtonは自動的に高さを変更してツールストリップに合わせます。
編集:ボタンのサイズだけでなく、ボタンの画像のサイズも大きくしたい場合は、大きい画像を使用するか、元の画像のサイズを変更してみることができます。次に、ツールストリップのImageScalingSize
プロパティも変更する必要があります。次のコードを使用してみてください:
//change the dimensions of button itself
toolStrip1.AutoSize = false; toolStrip1.Height = 50;
toolStripButton1.AutoSize = false; toolStripButton1.Width = 50;
//resize the image of the button to the new size
int sourceWidth = toolStripButton1.Image.Width;
int sourceHeight = toolStripButton1.Image.Height;
Bitmap b = new Bitmap(40, 40);
using (Graphics g = Graphics.FromImage((Image)b))
{
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.DrawImage(toolStripButton1.Image, 0, 0, 40, 40);
}
Image myResizedImg = (Image)b;
//put the resized image back to the button and change toolstrip's ImageScalingSize property
toolStripButton1.Image = myResizedImg;
toolStrip1.ImageScalingSize = new Size(40, 40);
ただ
toolStrip1.ImageScalingSize = new Size(40, 40);
それで全部です ;)
最も簡単な解決策:
プロパティツールバーのツールストリップのImageScalingSizeプロパティを変更するだけです。
それでおしまい :)