zoukankan      html  css  js  c++  java
  • 如何:拉伸 ToolStripTextBox 以填充 ToolStrip 的其余宽度(Windows 窗体)

    http://msdn.microsoft.com/zh-cn/library/ms404304.aspx   using System; using System.Drawing; using System.Windows.Forms; publicclass ToolStripSpringTextBox : ToolStripTextBox { publicoverride Size GetPreferredSize(Size constrainingSize) { // Use the default size if the text box is on the overflow menu // or is on a vertical ToolStrip. if (IsOnOverflow || Owner.Orientation == Orientation.Vertical) { return DefaultSize; } // Declare a variable to store the total available width as // it is calculated, starting with the display width of the // owning ToolStrip. Int32 width = Owner.DisplayRectangle.Width; // Subtract the width of the overflow button if it is displayed. if (Owner.OverflowButton.Visible) { width = width - Owner.OverflowButton.Width - Owner.OverflowButton.Margin.Horizontal; } // Declare a variable to maintain a count of ToolStripSpringTextBox // items currently displayed in the owning ToolStrip. Int32 springBoxCount = 0; foreach (ToolStripItem item in Owner.Items) { // Ignore items on the overflow menu. if (item.IsOnOverflow) continue; if (item is ToolStripSpringTextBox) { // For ToolStripSpringTextBox items, increment the count and // subtract the margin width from the total available width. springBoxCount++; width -= item.Margin.Horizontal; } else { // For all other items, subtract the full width from the total // available width. width = width - item.Width - item.Margin.Horizontal; } } // If there are multiple ToolStripSpringTextBox items in the owning // ToolStrip, divide the total available width between them. if (springBoxCount > 1) width /= springBoxCount; // If the available width is less than the default width, use the // default width, forcing one or more items onto the overflow menu. if (width < DefaultSize.Width) width = DefaultSize.Width; // Retrieve the preferred size from the base class, but change the // width to the calculated width. Size size = base.GetPreferredSize(constrainingSize); size.Width = width; return size; } } publicclass Form1 : Form { public Form1() { ToolStrip toolStrip1 = new ToolStrip(); toolStrip1.Dock = DockStyle.Top; toolStrip1.Items.Add(new ToolStripLabel("Address")); toolStrip1.Items.Add(new ToolStripSpringTextBox()); toolStrip1.Items.Add(new ToolStripButton("Go")); Controls.Add(toolStrip1); Text = "ToolStripSpringTextBox demo"; } } staticclass Program { [STAThread] staticvoid Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } }
  • 相关阅读:
    Google Earth 使用的经纬度格式及转换
    ADO.NET Entity Framework 一个简单数据绑定例子
    Oracle 异常 ORA01861: literal does not match format string(字符串格式不匹配)
    备份和还原 甲方 Oracle 数据库 问题一大堆
    使用 xsd.exe 命令工具 将 xsd架构 生成 类文件
    简单的源代码统计工具(统计源代码行数、工数、成本、质量指标统计)
    Google KML 起步教程笔记(二)高级 KML 文档与MIME 类型
    SQL Server 2008 中的空间数据存储
    PowerCmd 很好用的命令行工具,也许大家早就知道。
    Google Earth 本地地图缓存文件路径和KML文件路径
  • 原文地址:https://www.cnblogs.com/adodo1/p/4327329.html
Copyright © 2011-2022 走看看