如何在StatusStrip中右对齐控件?

时间:2009-02-03 23:44:32

标签: c# winforms statusstrip

我正试图在StatusStrip中右对齐一个控件。我怎么能这样做?

我没有看到在ToolStripItem控件上设置的属性,用于指定父StatusStrip上的物理对齐。

How do I get Messages drop down to be right aligned? http://i.friendfeed.com/ed90b205f64099687db30553daa79d075f280b90

9 个答案:

答案 0 :(得分:211)

在发布后几乎立即通过MSDN论坛找到它:)

通过将Text属性设置为string.Empty并将Spring属性设置为true,您可以使用ToolStripLabel伪右对齐控件。这将使其填满所有可用空间,并将所有控件推到ToolStripLabel的右侧。

答案 1 :(得分:5)

作为补充说明,这是因为在Win32 API中,单元格是固定宽度或填充剩余空间-1

int statwidths[] = {100, -1};

SendMessage(hStatus, SB_SETPARTS, sizeof(statwidths)/sizeof(int), (LPARAM)statwidths);
SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)"Hi there :)");

如果记忆正确地为我服务,那么每个状态栏只能有一个填充单元格(-1)。

您还可以添加第三个中间单元格,并为其指定fill属性以获得更加一致的StatusBar。一致,因为消息的左侧插入了您期望的位置。有点像MSDN page for StatusBars

上发现的mspaint镜头

我喜欢这种创意:D

答案 2 :(得分:4)

对我来说,它采取了两个简单的步骤:

  1. MyRightIntendedToolStripItem.Alignment设置为Right
  2. MyStatusStrip.LayoutStyle设置为HorizontalStackWithOverflow

答案 3 :(得分:3)

您可以使用以下逻辑在Button的末尾显示StatusStrip

  1. ToolstripLabel添加到StatusStrip
  2. 将文字设为string.Empty
  3. Padding
  4. 设置ToolstripLabel

    例如:

    this.toolStripStatusLabel1.Padding = new Padding((int)(this.Size.Width - 75), 0, 0, 0);
    

答案 4 :(得分:2)

保留一个Toolstrip标签,将Spring属性设置为true,并将BottomLeft

中的标签对齐文本设置为true

答案 5 :(得分:1)

我发现您可以将StatusStrip布局设置为Horizo​​ntalStackWithOverflow。 然后,对于右侧要在StatusStrip上的每个控件,将控件Alignment设置为Right。

我更喜欢这样做,因为您不需要任何额外的或虚拟的控件即可对齐。

答案 6 :(得分:0)

如果将状态条标签控件的Spring属性设置为true,则该标签将占用StatusStrip中其他控件未使用的任何空间。

答案 7 :(得分:-1)

将RightToLeft工具条属性设置为True。

答案 8 :(得分:-2)

我找到了在training_set = tf.contrib.learn.datasets.base.load_csv_with_header( filename=IRIS_TRAINING, target_dtype=np.int, features_dtype=np.float32) 中设置控件位置的一般方法。 您可以使用以下步骤在mnist = tf.contrib.learn.datasets.mnist.read_data_sets(train_dir=LOGDIR + 'data', one_hot=True) 的任意位置显示按钮。

  1. 将ToolstripLabel添加到StatusStrip
  2. 将文本设置为适当的空间量,如

      

    toolStripStatusLabel1.Text =“”;

  3. 如果布局不是您想要的,请转到步骤2以更改空间量 在StatusStrip中,其他工作已经完成。

相关问题