当前位置: 首页>>代码示例>>C#>>正文


C# Button.PerformClick方法代码示例

本文整理汇总了C#中System.Windows.Forms.Button.PerformClick方法的典型用法代码示例。如果您正苦于以下问题:C# Button.PerformClick方法的具体用法?C# Button.PerformClick怎么用?C# Button.PerformClick使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.Button的用法示例。


在下文中一共展示了Button.PerformClick方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AssignCommandToButton

        public void AssignCommandToButton()
        {
            CommandProvider.OnClickCount = 0;
            TestViewModel viewModel = new TestViewModel();
            using(var button = new Button()) {
                button.SetCommand(viewModel.TestCommand);
                Assert.That(viewModel.TestCommandExecuteCount, Is.EqualTo(0));

                button.PerformClick();
                Assert.That(viewModel.TestCommandExecuteCount, Is.EqualTo(1));
                Assert.That(viewModel.ExecuteParameter, Is.Null);
                Assert.That(viewModel.CanExecuteParameter, Is.Null);
                Assert.That(CommandProvider.OnClickCount, Is.EqualTo(1));

                button.SetCommand(null);
                button.PerformClick();
                Assert.That(viewModel.TestCommandExecuteCount, Is.EqualTo(1));
                Assert.That(CommandProvider.OnClickCount, Is.EqualTo(1));

                viewModel.CanExecuteTestCommand = false;
                button.SetCommand(viewModel.TestCommand);
                button.PerformClick();
                Assert.That(viewModel.TestCommandExecuteCount, Is.EqualTo(1));
                Assert.That(CommandProvider.OnClickCount, Is.EqualTo(1));

                viewModel.CanExecuteTestCommand = true;
                button.SetCommandParameter("param");
                button.PerformClick();
                Assert.That(viewModel.TestCommandExecuteCount, Is.EqualTo(2));
                Assert.That(viewModel.ExecuteParameter, Is.EqualTo("param"));
                Assert.That(viewModel.CanExecuteParameter, Is.EqualTo("param"));
                Assert.That(CommandProvider.OnClickCount, Is.EqualTo(2));
            }
        }
开发者ID:VitalyTVA,项目名称:WinMVVM,代码行数:34,代码来源:CommandProviderTests.cs

示例2: TestClickingTheButtonCallsClearOnCoinPurse

        public void TestClickingTheButtonCallsClearOnCoinPurse()
        {
            Button changeReturnButton = new Button();
            MockCoinPurse mockCoinPurse = new MockCoinPurse();

            new ReturnChangeButtonController(changeReturnButton,
                mockCoinPurse, new MockCoinReturn());

            changeReturnButton.PerformClick();

            Assert.AreEqual(1, mockCoinPurse.NumberOfTimesClearWasCalled);
        }
开发者ID:robbell5,项目名称:Vending-Machine-Kata,代码行数:12,代码来源:ReturnChangeButtonControllerTest.cs

示例3: TestClickingButtonCallsClearOnCoinReturn

        public void TestClickingButtonCallsClearOnCoinReturn()
        {
            Button clearCoinReturnButton = new Button();
            MockCoinReturn mockCoinReturn = new MockCoinReturn();

            ClearCoinReturnButtonController clearCoinReturnButtonController =
                new ClearCoinReturnButtonController(clearCoinReturnButton, mockCoinReturn, new MockDialogService());

            Assert.AreEqual(0, mockCoinReturn.NumberOfTimesClearWasCalled);

            clearCoinReturnButton.PerformClick();

            Assert.AreEqual(1, mockCoinReturn.NumberOfTimesClearWasCalled);
        }
开发者ID:robbell5,项目名称:Vending-Machine-Kata,代码行数:14,代码来源:ClearCoinReturnButtonControllerTest.cs

示例4: TestClickingButtonDoesNotDisplayDialogIfAmountReturnedIsZero

        public void TestClickingButtonDoesNotDisplayDialogIfAmountReturnedIsZero()
        {
            Button clearCoinReturnButton = new Button();
            MockCoinReturn mockCoinReturn = new MockCoinReturn();
            MockDialogService mockDialogService = new MockDialogService();

            mockCoinReturn.ValueToReturnFromClear = 0;

            new ClearCoinReturnButtonController(clearCoinReturnButton, mockCoinReturn, mockDialogService);

            Assert.AreEqual(0, mockDialogService.NumberOfTimesShowMessageWasCalled);

            clearCoinReturnButton.PerformClick();

            Assert.AreEqual(0, mockDialogService.NumberOfTimesShowMessageWasCalled);
        }
开发者ID:robbell5,项目名称:Vending-Machine-Kata,代码行数:16,代码来源:ClearCoinReturnButtonControllerTest.cs

示例5: Test_WeakMethodBinding_SourceMethod

        public void Test_WeakMethodBinding_SourceMethod()
        {
            var viewModel = new TestViewModel();
            var button = new Button();

            new WeakMethodBinding(viewModel, null, button, null)
                .Initialize<WeakMethodBinding>()
                .AttachTargetMethod("AddAge", null)
                .AttachTargetCanInvokeMethod("CanAddAge", null)
                .AttachSourceEvent("Click");

            Assert.AreEqual(0, viewModel.Age);

            button.PerformClick();

            Assert.AreEqual(1, viewModel.Age);
        }
开发者ID:zhouyongh,项目名称:BindingEngine,代码行数:17,代码来源:WeakMethodBindingTests.cs

示例6: TestClickingButtonDisplaysDialogInformingUserOfAmountReturedFromClear

        public void TestClickingButtonDisplaysDialogInformingUserOfAmountReturedFromClear(decimal amountReturnedByCoinReturn, string expectedFormatedAmount)
        {
            Button clearCoinReturnButton = new Button();
            MockCoinReturn mockCoinReturn = new MockCoinReturn();
            MockDialogService mockDialogService = new MockDialogService();

            mockCoinReturn.ValueToReturnFromClear = amountReturnedByCoinReturn;
            string expectedDialogText = "You receive: " + expectedFormatedAmount;

            new ClearCoinReturnButtonController(clearCoinReturnButton, mockCoinReturn, mockDialogService);

            Assert.AreEqual(0, mockDialogService.NumberOfTimesShowMessageWasCalled);

            clearCoinReturnButton.PerformClick();

            Assert.AreEqual(1, mockDialogService.NumberOfTimesShowMessageWasCalled);
            Assert.AreEqual(expectedDialogText, mockDialogService.LastMessageShown);
        }
开发者ID:robbell5,项目名称:Vending-Machine-Kata,代码行数:18,代码来源:ClearCoinReturnButtonControllerTest.cs

示例7: TestClickingTheButtonPassesTheCoinsReturnedFromClearToTheCoinReturn

        public void TestClickingTheButtonPassesTheCoinsReturnedFromClearToTheCoinReturn()
        {
            Button changeReturnButton = new Button();
            MockCoinPurse mockCoinPurse = new MockCoinPurse();
            MockCoinReturn mockCoinReturn = new MockCoinReturn();

            List<ICoin> coinsFromCoinPurse = new List<ICoin>() {new MockCoin(), new MockCoin()};
            mockCoinPurse.CoinsToReturnFromClear = coinsFromCoinPurse;

            new ReturnChangeButtonController(changeReturnButton,
                mockCoinPurse, mockCoinReturn);

            changeReturnButton.PerformClick();

            List<ICoin> coinsPassedToCoinReturn = mockCoinReturn.CoinsPassedToAddCoin;

            Assert.AreEqual(coinsFromCoinPurse.Count, coinsPassedToCoinReturn.Count);

            foreach (ICoin coinFromCoinPurse in coinsFromCoinPurse)
                Assert.Contains(coinFromCoinPurse, coinsPassedToCoinReturn);
        }
开发者ID:robbell5,项目名称:Vending-Machine-Kata,代码行数:21,代码来源:ReturnChangeButtonControllerTest.cs

示例8: UpdateIsEnabledOnCanExecuteChanged

 public void UpdateIsEnabledOnCanExecuteChanged()
 {
     bool canExecute = true;
     bool executed = false;
     var command = new DelegateCommand<string>(o => executed = true, o => canExecute);
     using(var button = new Button()) {
         button.SetCommand(command);
         Assert.That(button.Enabled, Is.True);
         canExecute = false;
         Assert.That(button.Enabled, Is.True);
         button.PerformClick();
         Assert.That(executed, Is.False);
         Assert.That(button.Enabled, Is.True);
         TestUtils.GarbageCollect();
         command.RaiseCanExecuteChanged();
         Assert.That(button.Enabled, Is.False);
         Assert.That(command.CanExecuteChangedSubscribeCount, Is.EqualTo(1));
         WeakReference handlerRef = GetHandlerRef(button);
         button.SetCommand(null);
         Assert.That(command.CanExecuteChangedSubscribeCount, Is.EqualTo(0));
         TestUtils.GarbageCollect();
         Assert.That(handlerRef.IsAlive, Is.False);
     }
 }
开发者ID:VitalyTVA,项目名称:WinMVVM,代码行数:24,代码来源:CommandProviderTests.cs

示例9: ClickButton

 public void ClickButton(Button button)
 {
     if (!button.Visible)
     {
         throw new NotSupportedException();
     }
     CheckDisposed();
     button.PerformClick();
 }
开发者ID:lgatto,项目名称:proteowizard,代码行数:9,代码来源:AlertDlg.cs

示例10: addNotifyIconButton

 private void addNotifyIconButton(Button button)
 {
     var tsButton = new ToolStripMenuItem();
     tsButton.Text = button.Text;
     tsButton.Enabled = button.Enabled;
     button.EnabledChanged += (sender, e) =>
      {
          tsButton.Enabled = button.Enabled;
      };
     tsButton.Click += (sender, e) =>
       {
           button.PerformClick();
       };
     currentToolStripItemCollection.Add(tsButton);
 }
开发者ID:aaasoft,项目名称:Quick.OwinMVC,代码行数:15,代码来源:MainForm.cs

示例11: Test_WeakNotify_TwoWay

        public void Test_WeakNotify_TwoWay()
        {
            var button = new Button();
            var view = new TestView();

            int changedCount = 0;
            int targetCount = 0;

            new WeakNotifyBinding(view, null, button, null)
                .Initialize<WeakNotifyBinding>()
                .AttachTargetEvent("TestViewEvent")
                .AttachSourceEvent("Click")
                .OfType<WeakNotifyBinding>()
                .SetTargetChanged((source, args) => { changedCount++; })
                .SetSourceChanged((source, args) => { targetCount++; });

            Assert.AreEqual(0, changedCount);

            view.RaiseTestViewEvent();
            Assert.AreEqual(1, changedCount);

            button.PerformClick();
            Assert.AreEqual(1, targetCount);
        }
开发者ID:zhouyongh,项目名称:BindingEngine,代码行数:24,代码来源:WeakNotifyBindingTests.cs

示例12: PerformClickTest

		public void PerformClickTest ()
		{
			Form f = new Form ();
			f.ShowInTaskbar = false;
			Button B1 = new Button ();
			B1.Text = "DialogResult";
			B1.Visible = true;
			f.Controls.Add (B1);
			B1.PerformClick ();
			Assert.AreEqual (DialogResult.None, B1.DialogResult, "#7");
			f.Dispose ();
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:12,代码来源:ButtonTest.cs

示例13: Test_WeakBinding_AttachSourceEvent_2

        public void Test_WeakBinding_AttachSourceEvent_2()
        {
            var viewModel = new TestViewModel();
            var view = new TestView();
            var button = new Button();

            WeakBinding binding = new WeakPropertyBinding(viewModel, "Name", view, "Text1")
                .Initialize<WeakPropertyBinding>()
                .SetMode(BindMode.OneWay)
                .AttachSourceEvent(button, "Click");

            view.Text1 = Name1;
            Assert.AreNotEqual(viewModel.Name, Name1);

            button.PerformClick();
            Assert.AreEqual(viewModel.Name, Name1);
            binding.Clear();

            viewModel = new TestViewModel();
            view = new TestView();
            button = new Button();

            new WeakPropertyBinding(viewModel, "Name", view, "Text1")
                .Initialize<WeakPropertyBinding>()
                .SetMode(BindMode.OneWay)
                .AttachSourceEvent(button, null, "Click");

            view.Text1 = Name1;
            Assert.AreNotEqual(viewModel.Name, Name1);

            button.PerformClick();
            Assert.AreEqual(viewModel.Name, Name1);
        }
开发者ID:zhouyongh,项目名称:BindingEngine,代码行数:33,代码来源:WeakBindingTests.cs

示例14: BasicPropertiesTest

		public void BasicPropertiesTest ()
		{
			SWF.HelpProvider swfHelpProvider = new SWF.HelpProvider ();
			
			SWF.Button swfButton = new SWF.Button ();
			swfButton.Location = new SD.Point (3, 3);
			swfButton.Size = new SD.Size (272, 72);
			swfButton.Text = "With help";
			
			SWF.Button swfButtonNoHelp = new SWF.Button ();
			swfButtonNoHelp.Location = new SD.Point (3, 30);
			swfButtonNoHelp.Size = new SD.Size (272, 72);
			swfButtonNoHelp.Text = "No help";
			
			//We have to use an event to fake the user click
			swfButton.Click += new System.EventHandler (OnControlClicked);

			swfHelpProvider.SetShowHelp (swfButton, true);
			swfHelpProvider.SetHelpString (swfButton, "I'm showing a button tooltip.");
			
			Form.Controls.Add (swfButton);
			Form.Controls.Add (swfButtonNoHelp);
			
			//Testing ToolTipOpenedEvent
			bridge.ResetEventLists ();
			swfButton.PerformClick (); //Clicking the button will fake the event!

			StructureChangedEventTuple eventTuple 
				= bridge.GetStructureChangedEventAt (0, StructureChangeType.ChildAdded);
			Assert.IsNotNull (eventTuple, "GetAutomationEventAt (0)");
			
			//We have the HelpProvider!
			IRawElementProviderFragment helpProvider = eventTuple.provider as IRawElementProviderFragment;
			
			Assert.IsNotNull (helpProvider, "helpProvider is null");
			
			TestProperty (helpProvider,
			              AutomationElementIdentifiers.IsControlElementProperty,
			              true);
			
			TestProperty (helpProvider,
			              AutomationElementIdentifiers.IsContentElementProperty,
			              false);			

			TestProperty (helpProvider,
			              AutomationElementIdentifiers.HelpTextProperty,
			              null);

			TestProperty (helpProvider,
			              AutomationElementIdentifiers.LocalizedControlTypeProperty,
			              "tool tip");
			
			TestProperty (helpProvider,
			              AutomationElementIdentifiers.ControlTypeProperty,
			              ControlType.ToolTip.Id);
			
			TestProperty (helpProvider,
			              AutomationElementIdentifiers.LabeledByProperty,
			              null);
			
			TestProperty (helpProvider,
			              AutomationElementIdentifiers.NameProperty,
			              swfHelpProvider.GetHelpString (swfButton));
			
			TestProperty (helpProvider,
			              AutomationElementIdentifiers.IsKeyboardFocusableProperty,
			              false);
			
			TestProperty (helpProvider,
			              AutomationElementIdentifiers.ClickablePointProperty,
			              null);

			// TODO: How to allow it?
//			bridge.ResetEventLists ();
//
//			swfButtonNoHelp.PerformClick (); //Clicking this button will close the tooltip
//			
//			Assert.AreEqual (1,
//			                 bridge.GetAutomationEventCount (InvokePatternIdentifiers.InvokedEvent),
//			                 "AutomationElementIdentifiers.InvokedEvent");
//	
//			Assert.IsNotNull (bridge.GetStructureChangedEventAt (0, StructureChangeType.ChildRemoved),
//			                 "AutomationElementIdentifiers.ChildRemoved");
		}
开发者ID:mono,项目名称:uia2atk,代码行数:84,代码来源:HelpProviderTest.cs

示例15: ExecuteShortCutKey

 /// <summary>
 /// For shortcut keys
 /// </summary>
 /// <param name="e"></param>
 /// <param name="btn"></param>
 /// <param name="btnclose"></param>
 public static void ExecuteShortCutKey(KeyEventArgs e, Button btn, Button btnclose)
 {
     if (e.KeyCode == Keys.Escape)
     {
         btnclose.PerformClick();
     }
     if (e.KeyCode == Keys.S && Control.ModifierKeys == Keys.Control) //Save
     {
         btn.PerformClick();
     }
 }
开发者ID:JaseelAM,项目名称:OpenMiracle-Three-Tier,代码行数:17,代码来源:Common.cs


注:本文中的System.Windows.Forms.Button.PerformClick方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。