フォームに最初に追加されたときにのみ起動するUserControlのイベントはありますか?私は基本的にフォームにコントロールを追加した後、コントロールをユーザーに使用する方法についてのメモを表示したいが、その後は表示しない(このコントロールの別のインスタンスを追加するまで)。UserControlのOnAddedToFormデザイナーイベント?
0
A
答えて
0
それを行う簡単な方法は次のようになります。
Control
からイベントParentChanged
を使用してください:Control.ParentChanged Event
UserControl
あなたUserControl
でControl
のヘリタンスで、あなたがするプライベートフィールドを使用することができますアイテムが既に親に追加されているかどうかを定義します。
このコードは、あなたのために働くことができます:メモが見えるとは
public class CustomUserControl : UserControl
{
private bool _firstTimeAdded = false;
private void Init()
{
this.ParentChanged += CustomUserControl_ParentChanged;
}
private void CustomUserControl_ParentChanged(object sender, EventArgs e)
{
if (Parent is Form && !_firstTimeAdded)
{
_firstTimeAdded = true;
// Show your memmo
}
}
}
+0
いいえ、それは動作しません - それはフォームのデザイナーを開くたびに起動します(これは私が必要とするデザイナーモードです)。 – cubrman
関連する問題
- 1. MVVM + UserControl + UserControl + DependencyProperty
- 2. のUserControlのDataContext
- 3. カスタムのusercontrol textbox.text
- 4. UserControlのAJAX ScriptManager
- 5. UserControlオブジェクトのキャッシュ
- 6. UserControlへのデータバインディング
- 7. ItemsControlのUsercontrolバリデーション
- 8. WebControlのUserControlイベント
- 9. DependencyProperty UserControlのbool
- 10. WPFのC#UserControl
- 11. WebFormのWinform usercontrol
- 12. UserControlのアンロード
- 13. HTMLドキュメントのUserControl
- 14. ASP.NET UserControlのjQuery
- 15. UserControlのDebugVisualizer
- 16. UserControlトリガーのカスタムプロパティ
- 17. タブレットデバイスのUserControlスクロールパフォーマンス
- 18. Usercontrolデータソース?
- 19. UserControlグローバリゼーション
- 20. UserControl Position
- 21. UserControlプロパティ
- 22. WPF usercontrol
- 23. web userControl
- 24. VB.NET UserControl
- 25. aspx.netのusercontrolのポップアップウィンドウ
- 26. UserControlのテキストボックスのバインディングマージン
- 27. 別のUserControl内のUserControlのプロパティにバインドする方法は?
- 28. UserControlの動的イベント
- 29. txtファイル内のUserControl
- 30. WPFのDependencyPropertyとUserControl
を表示する必要がありますどのように?私は、あなたはuserControl(https://msdn.microsoft.com/en-us/library/35ea88wb(v=vs.110).aspx)のカスタムデザイナーを作成し、メモをそこに追加することができると思います。 – ASh
単純なMessageBoxが行います。 – cubrman