Open Windows' Calculator in my C# Win Application?

前端 未结 6 1549
感动是毒
感动是毒 2020-12-31 13:41

I know I can open Windows Calculator with the following code :

System.Diagnostics.Process.Start(\"calc\");

But I wanna open it in my C# Win

6条回答
  •  [愿得一人]
    2020-12-31 14:25

    You cannot embed another application into your form.

    However, you can move the calculator window on top of your form and set your form as its parent. This might accomplish the visual effect that you're looking for. You might check into the SetParent API function. For example:

    System.Diagnostics.Process p = System.Diagnostics.Process.Start("calc.exe");
    p.WaitForInputIdle();
    NativeMethods.SetParent(p.MainWindowHandle, this.Handle);
    

    A better solution might be just to roll your own calculator control in C# if you really need that functionality embedded in your app. Banging together a simple calculator really isn't at all difficult, and its infinitely customizable to do and look exactly as you want.

    Something like this, perhaps, would be a good starting point if you wanted to roll your own calculator: http://www.codeproject.com/KB/cs/Scientific_Calculator.aspx

    And I've always thought this type of a control would be ridiculously useful someday if I ever wrote an app that relied heavily on numerical input: http://www.codeproject.com/KB/miscctrl/C__Popup_Calculator.aspx

提交回复
热议问题