Author Topic: How to call a Windows Forms Application  (Read 4075 times)

0 Members and 1 Guest are viewing this topic.

Coder

  • Swamp Rat
  • Posts: 827
How to call a Windows Forms Application
« on: April 15, 2015, 09:06:01 AM »
Hello Guys ,

I have started learning VB.net and have a very simple program to draw a line , I started with AutoCAD plug-in and everything works great .

Is there a way to add / call or create a dialog by calling the Windows Forms Application from my current program instead of starting a new file with Windows Forms Application then
copy & paste the codes there and adding a reference and changing the preferences to false and so on ?

Many thanks .

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: How to call a Windows Forms Application
« Reply #1 on: April 15, 2015, 10:01:55 AM »
Unless I am misunderstanding your question, the answer is yes.

You can add the application whose form it is you want to use, as a reference, then call it like you would any other form. Keep in mind that you would be somewhat restricted to the original developers code.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Coder

  • Swamp Rat
  • Posts: 827
Re: How to call a Windows Forms Application
« Reply #2 on: April 15, 2015, 11:29:26 AM »
Thank you Keith for your reply .

I tried to ADD a new Windows Forms Application from the my current class ( AutoCAD plug-in ) but I couldn't find that application in the ADD command , how would you call  the Windows form Class file ?

Thank you .

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: How to call a Windows Forms Application
« Reply #3 on: April 15, 2015, 01:32:38 PM »
STOP! If you're just learning VB.Net then I assume you've just started learning WinForms too.  Stop learning WinForms and learn WPF instead. WPF takes a little longer to learn but once you start understanding it, building UIs will get faster. The binding alone would keep me from ever using WinForms again.  The true power comes from using the MVVM pattern and truly being able to separate the UI from the code behind.  WinForms uses old Windows based graphics.  WPF uses the DirectX engine which will give you greater speed and usability. 

And while you're at it stop learning VB and learn C# instead. VB.NET is a go no where language. None of the skills you learn from VB.NET translate to other languages.  C# , Java, JavaScript, Swift (objective C), and C++ all follow similar notation.  Its an easy learning curve to go from one of these to the other.  I also remember reading that some newer features of ASP.NET are in C# only.

These comments are just my opinion but every time someone comes to me who is just starting to get into programing I do my best to keep them away from VB.NET.
Revit 2019, AMEP 2019 64bit Win 10

CADbloke

  • Bull Frog
  • Posts: 342
  • Crash Test Dummy
Re: How to call a Windows Forms Application
« Reply #4 on: April 15, 2015, 07:28:09 PM »
While not trying to start any sort of flame war here, I agree with MexicanCustard. I started with VBA and later adopted C#. All of his points are valid about VB / C# and I would add the the vast majority of open-source .NET code and samplec is in C#, most architecture discussion leans on C# / C++ style languages. Consider it like speaking English, you're have an advantage if it is your first language, you will get a lot of value from understanding it at all, you are at a severe disadvantage if you don't understand any of it. Personally, I find VB quite wordy compared to C#, I can read C# much faster than VB (and a lot faster again than Lisp).

THe WinForms / WPF argument is a little less clear-cut but I also concur here - the learning curve for WPF is somewhat steep but I think it is/was worth it. The WPF paradigm is also more like the paradigm for building web apps, at least a lot more so than Winforms. The real trick with WPF is to build an application that can run without the UI, only then you will know you have really separated your concerns.  The application logic drives the UI (via binding), not the other way around. Why is this a big deal? Easy example: your application can run in the Core Console with minimal changes just by leaving out the UI, you can't do that with an application where all the logic is in code-behind classes. Your application could run as a web service on Autocad.IO, also with minimal changes.

My app in a palette in the screenshot at http://www.theswamp.org/index.php?topic=49267.msg543726#msg543726 (not RegexBuddy, the bottom one) is WPF, it also runs in the Core Console by presenting its functions as Lisp methods and has a public C# API so I can call it from other things I write, I literally just left out the UI to create teh Core Console version. Also, by doing this I can port it to IntelliCAD, BricsCAD, NanoCAD etc quite easily. By really separating all my concerns (and programming against Interfaces) I can also potentially port it to a completely different application (Excel, for instance). That's a bigger change but it's a migration, not a rewrite. No, I haven't considered it. YET.

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: How to call a Windows Forms Application
« Reply #5 on: April 15, 2015, 08:44:31 PM »
Thank you Keith for your reply .

I tried to ADD a new Windows Forms Application from the my current class ( AutoCAD plug-in ) but I couldn't find that application in the ADD command , how would you call  the Windows form Class file ?

Thank you .

If I understand this question correctly I think you want to be able to open a windows form from your autocad plug  in dll?

You have 3 base types of projects templates in VS, a console app, Windows From Application and a Class Library.

As you know your Autocad plug in needs to be a Class Library and if you want to use a Windows Form then you don't add an application, you add a new component (right click on your project in the Solution explorer and choose Add or select Windows Form).
You will see the form in your project and there you can edit the controls etc for use in your plug in.

To open this form, in your command handler you create the new form and show it
Code - C#: [Select]
  1. [CommandMethod("MYFORM")]
  2.         public static void ShowForm()
  3.         {
  4.             MyForm form = new MyForm();
  5.             form.Show();
  6.         }
  7.  

Obviously there's a bit more to understand than that but it's a start.

The previous posts about WPF are worth your consideration also and will require more study, good luck!
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

Coder

  • Swamp Rat
  • Posts: 827
Re: How to call a Windows Forms Application
« Reply #6 on: April 16, 2015, 12:51:51 AM »
Thank you guys for you greatly valuable replies , you are really amazing  :-)

MexicanCustard your inputs is really great and I will strongly take your advise in consideration , but I need to get my vehicle started first with something usefully working then from that point I can then jump to the other vehicle easily to be side by side with the community  ;-)

Many thanks for taking the time to describe the differences between these two forms in details .

CADbloke thank you for that extra input about the same point that MexicanCustard 's did .

MickD thank you , that is what I was searching for , it helps much . thanks for your hard work on the photos .

I am proud to be a member in this education forum with these great members indeed .

Thank you all once again .