[英]use multiple screens on a window - C#
我想在一个窗口上使用多个屏幕( panel
或其他任何东西)!
我不想使用MDI Child Form
...
还有另一种方法吗?
对于显示的第二种情况,可以使用选项卡控件,其中选项卡垂直显示:
将一个TabControl添加到您的窗体。
将Alignment属性设置为Right。
将SizeMode属性设置为Fixed,以便所有选项卡都具有相同的宽度。
将ItemSize属性设置为选项卡的首选固定大小。 请记住,尽管选项卡是右对齐的,但它们的行为就像选项卡在顶部一样。 因此,为了使选项卡变宽,必须更改Height属性,为了使它们变高,必须更改Width属性。
在下面的代码示例中,“宽度”设置为25,“高度”设置为150。
将DrawMode属性设置为OwnerDrawFixed。
为TabControl的DrawItem事件定义一个处理程序,该处理程序从左到右呈现文本。
private void TabControl1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
Graphics g = e.Graphics;
Brush _TextBrush = default(Brush);
// Get the item from the collection.
TabPage _TabPage = TabControl1.TabPages(e.Index);
// Get the real bounds for the tab rectangle.
Rectangle _TabBounds = TabControl1.GetTabRect(e.Index);
if ((e.State == DrawItemState.Selected))
{
// Draw a different background color, and don't paint a focus rectangle.
_TextBrush = new SolidBrush(Color.Red);
g.FillRectangle(Brushes.Gray, e.Bounds);
}
else
{
_TextBrush = new System.Drawing.SolidBrush(e.ForeColor);
e.DrawBackground();
}
// Use our own font.
Font _TabFont = new Font("Arial", 10.0, FontStyle.Bold, GraphicsUnit.Pixel);
// Draw string. Center the text.
StringFormat _StringFlags = new StringFormat();
_StringFlags.Alignment = StringAlignment.Center;
_StringFlags.LineAlignment = StringAlignment.Center;
g.DrawString(_TabPage.Text, _TabFont, _TextBrush, _TabBounds, new StringFormat(_StringFlags));
}
我们的方法是将“视图”创建为UserControl
,然后在代码中将其添加到表单面板或从表单面板中删除。 大多数情况下,它们共享一组通用方法(接口IView
),因此我们可以例如检查视图是否为未保存的数据等。
尝试使用Tab键控制。 希望它适合您的要求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.