gtk#Vbox没有显示

时间:2018-07-30 10:28:23

标签: gtk#

我正在尝试在我的gtk#应用程序中建立2个VBox。问题是,它们根本没有出现。我看不到按钮。我在做什么错了?

<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="10000"
android:versionName="1.0.0"
android:hardwareAccelerated="true"
package="de.myapp.app">

<uses-sdk
    android:minSdkVersion="19"
    android:targetSdkVersion="27" />

<supports-screens
    android:anyDensity="true"
    android:smallScreens="true"
    android:normalScreens="true"
    android:largeScreens="true"
    android:resizeable="true"
    android:xlargeScreens="true" />

<uses-permission
    android:name="android.permission.INTERNET" />

<application
    android:label="@ref/0x7f030001"
    android:icon="@ref/0x7f020000"
    android:debuggable="true"
    android:hardwareAccelerated="true"
    android:supportsRtl="true">

    <activity
        android:theme="@ref/0x01030129"
        android:label="@ref/0x7f030000"
        android:name="de.myapp.app.MainActivity"
        android:launchMode="1"
        android:configChanges="0x4b4"
        android:windowSoftInputMode="0x10">

        <intent-filter
            android:label="@ref/0x7f030002">

            <action
                android:name="android.intent.action.MAIN" />

            <category
                android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
</manifest>

我尝试了我能想到的Add和ShowAll的所有可能组合。

1 个答案:

答案 0 :(得分:0)

您应该只使用一次Window.Add(),添加包含的小部件(一个 VBox 或类似的工具),然后在其中使用Box.PackStart()Box.PackEnd()方法该容器以创建复杂的布局。

    Build();
    this.Title = "Kassa";

    VBox container = new VBox();
    left = new VBox();
    right = new VBox(true, 0);

    Button button = new Button( "b" );
    right.Add(button);
    right.PackStart( button, true, false, 0 );

    container.PackStart( left, true, true, 5 );
    container.PackStart( right, true, true, 5 );

    this.Add( container );
    this.ShowAll();

如果以相反的顺序添加了框,则会看到一个巨大的按钮占据了整个屏幕。原因是Window.Add()仅添加了一个项目,如果您两次调用它,则前者被遗忘,而后者则使用了……完全没有任何内容的项目(前者有一个按钮),从而产生了幻觉。什么也没显示。

希望这会有所帮助。

相关问题