2011-10-28 25 views
2

Possible Duplicate:
Update label location in C#?非可調用成員

我創建一個自定義的Windows窗體,並試圖更改標籤的位置,我得到的錯誤時:錯誤1非可調用成員的System.Windows.Forms.Control.Location '不能像一種方法一樣使用。 C:\ Users \用戶然\文件\的Visual Studio 2010 \項目\ SyncCustomForm \ SyncCustomForm \ SyncControl1.cs 50 24 SyncCustomForm

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Drawing; 
using System.Data; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 

namespace SyncCustomForm 
{ 
    public partial class SyncControl : UserControl 
    { 

     public SyncControl() 
     { 
      InitializeComponent(); 
     } 

     public ProgressBar prbSyncProgress 
     { 
      get { return prbProgress; } 
     } 
     public Label lblException 
     { 
      get { return lblMessage; } 
     } 
     public Label lblStatus 
     { 
      get { return lblS; } 
     } 
     public Button btnPause 
     { 
      get { return btnP; } 
     } 
     public Button btnStop 
     { 
      get { return btnS; } 
     } 
     public GroupBox grbxSync 
     { 
      get { return gbxSync; } 
     } 

     private void SyncControl_Load(object sender, EventArgs e) 
     { 

      lblMessage.Location.X = 50; 
     } 
    } 
} 
+0

爲什麼要公開所有私有部分?就像在現實生活中一樣,在編程時也強烈建議不要...(我指的是你的公共標籤,按鈕等。 – Crisfole

回答

2

Location屬性是一個結構和X是結構的屬性,並且在該如果您不能獨立設置X的值。

你需要這樣做:

lblMessage.Location = new Point(50, 50); // both X and Y will be set this way 

,或者如果你只想設置X值,設置Left屬性:如果你有一個結構的

lblMessage.Left = 50; 

只能設置屬性直接引用該結構:

var loc = lblMessage.Location; 
loc.X = 50; 
lblMessage.Location = loc; 
+0

非常感謝你 – maryum375

相關問題