Bagikan melalui


CustomTaskPane.Width Properti

Definisi

Mendapatkan atau mengatur lebar panel tugas kustom, dalam poin.

public:
 property int Width { int get(); void set(int value); };
public int Width { get; set; }
member this.Width : int with get, set
Public Property Width As Integer

Nilai Properti

Lebar panel tugas kustom, dalam titik.

Pengecualian

Nilai DockPosition properti adalah Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionTop atau Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionBottom saat Anda mencoba mengatur Width properti.--atau-Anda mencoba mengatur Width properti di penanganan aktivitas untuk DockPositionChanged peristiwa atau VisibleChanged .

Metode Microsoft.Office.Tools.CustomTaskPane.Dispose dari telah dipanggil CustomTaskPane .

Contoh

Contoh kode berikut membuat panel tugas kustom yang memiliki lebar default yang berbeda saat ditampilkan di depan jendela aplikasi aktif, dan saat ditautkan ke sisi kiri atau kanan jendela. Contoh kode ini adalah bagian dari contoh yang lebih besar yang disediakan untuk CustomTaskPane.

private MyUserControl myUserControl1;
private Microsoft.Office.Tools.CustomTaskPane myCustomTaskPane;

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
    myUserControl1 = new MyUserControl();
    myCustomTaskPane = this.CustomTaskPanes.Add(myUserControl1,
        "New Task Pane");

    myCustomTaskPane.DockPosition =
        Office.MsoCTPDockPosition.msoCTPDockPositionFloating;
    myCustomTaskPane.Height = 500;
    myCustomTaskPane.Width = 500;

    myCustomTaskPane.DockPosition =
        Office.MsoCTPDockPosition.msoCTPDockPositionRight;
    myCustomTaskPane.Width = 300;

    myCustomTaskPane.Visible = true;
    myCustomTaskPane.DockPositionChanged +=
        new EventHandler(myCustomTaskPane_DockPositionChanged);
}
Private myUserControl1 As MyUserControl
Private WithEvents myCustomTaskPane As Microsoft.Office.Tools.CustomTaskPane

Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) _
    Handles Me.Startup

    myUserControl1 = New MyUserControl()
    myCustomTaskPane = Me.CustomTaskPanes.Add(myUserControl1, "New Task Pane")

    With myCustomTaskPane
        .DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionFloating
        .Height = 500
        .Width = 500
        .DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionRight
        .Width = 300
        .Visible = True
    End With
End Sub

Keterangan

Jangan gunakan Width properti jika panel tugas kustom ditampar ke bagian atas atau bawah jendela dokumen. DockPosition Jika properti adalah Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionTop atau Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionBottom, Width properti mengembalikan 0 dan melempar COMException jika Anda mencoba mengaturnya.

Lebar maksimum tergantung pada posisi dock. Saat panel tugas kustom ditampar ke kiri atau kanan jendela dokumen, lebar maksimum sekitar setengah dari lebar layar. Saat panel tugas kustom mengambang, tidak ada lebar maksimum.

Lebar minimum bergantung pada beberapa faktor, dan dapat berubah dalam rilis Microsoft Office di masa mendatang. Jika Anda mencoba mengatur Width properti ke nilai yang kurang dari lebar minimum, aplikasi akan secara otomatis menetapkan Width ulang properti ke lebar minimum.

Berlaku untuk