如何停靠按钮,以便可以根据表单进行调整 [英] how to dock button so that it can adjust with the form

查看:43
本文介绍了如何停靠按钮,以便可以根据表单进行调整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,有人可以帮我吗?
我不知道如何在项目的主要形式中使用停靠按钮

pliz发送至我的电子邮件:[DELETED] @ yahoo.co.in


[edit]除非您真的喜欢垃圾邮件,否则请不要在任何论坛中发布您的电子邮件地址!如果有人回复您,您将收到一封电子邮件,通知您-OriginalGriff [/edit]

Hello there can anyone help me?
I dont know how to use dock button in my main form of my project

pliz send to my email: [DELETED]@yahoo.co.in


[edit]Never post your email address in any forum, unless you really like spam! If anyone replies to you, you will receive an email to let you know - OriginalGriff[/edit]

推荐答案

始终需要使用对接技术,如果要使表单布局保持一致.您还将需要大量面板.

我将在没有Designer的情况下以代码形式显示所有内容,因此您将看到它是如何完成的:

You always need to use Docking technique if you want to make consistent form Layout. You will also need plenty of Panels.

I''ll show this all in code, without Designer, so you would see how it is really done:

using System;
using System.Drawing;
using System.Windows.Forms;

public partial class FormMain : Form {
    
    public FormMain() {
        InitializeComponent();
        Setup();
    } //FormMain

    void Setup() {
        Panel left = new Panel();
        this.Padding = new Padding(10);
        left.BackColor = Color.Yellow;
        left.Dock = DockStyle.Left;
        Panel right = new Panel();
        right.BackColor = Color.Wheat;
        right.Dock = DockStyle.Fill;
        right.Padding = new Padding(4);
        Button button = new Button();
        button.Dock = DockStyle.Bottom;
        button.Text = "&Click it!";
        button.Click += delegate(object sender, EventArgs eventArgs) {
            MessageBox.Show("Clicked!");
        };
        button.BackColor = Color.LightGray;
        ListBox lb = new ListBox();
        lb.Dock = DockStyle.Fill;
        right.Controls.AddRange(new Control[] { lb, button, });
        this.Controls.Add(right);
        this.Controls.Add(left);
    } //Setup

    [STAThread]
    static void Main() {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new FormMain());
    } //Main (entry point)

} //class FormMain



我用颜色来显示控制权在哪里.在设计阶段在临时基础上使用颜色也是一个很好的工具.设计适当的填充特别有用.稍后,您将删除颜色.

有关更多设计指导,请参阅我过去的解决方案:
GUI外观-C#.Net [屏幕分辨率更改时,Zom Out发生故障 [ ^ ],
类实现背后的代码 [



I used colors to show what control goes where. IUsing colors on temporary bases is also a good tool during design phase. It is especially useful to design proper padding. Later on, you will remove the colors.

For further design directions, please see my past solutions:
GUI Apperance - C#.Net[^],
Zom Out malfunctions when Screen resolution changes[^],
Code behind class implementation[^].

—SA


根据您实际想要执行的操作,您可能会发现Anchor属性对于按钮而言效果更好.

Dock将用对象填充表单的那一侧:因此,如果将按钮停靠在左侧,它将从顶部到底部填充te表单的左侧-对于按钮不是一个好主意!

如果您使用
锚点 [
Depending on what you actually want to do, you may find the Anchor property works better for buttons.

Dock will fill that side of the form with the object: so if you Dock a button to the left, it will fill the left hand side of te form, from the top to the bottom - not a good idea for a button!

If you play with the Anchor[^] settings, you can make the button expand and contract with the form, or fix it relative to the bottom or right. Give it a go: the effects are immediate, so you can play and see what happens in the designer.


这篇关于如何停靠按钮,以便可以根据表单进行调整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆