DOT.NET code again #xpa


Adrian Wick
 

Dear wizards.

can someone, for the love of God, explain to me how to code 3rd line of the following code in xpa (Controls.Add(simpleButton)).

private void CreateSimpleButton(int left, int top) { SimpleButton simpleButton = new SimpleButton(); Controls.Add(simpleButton); simpleButton.Text = "Show Settings Page"; simpleButton.ImageOptions.ImageList = imageCollection1; simpleButton.ImageOptions.ImageIndex = 0; simpleButton.Padding = new Padding(10); simpleButton.AutoSize = true; simpleButton.Location = new Point(left, top); simpleButton.Click += SimpleButton_Click; }

To me it looks like i need a Controls dotnet variable and add this button to the Controls. The button is on my form, but it has no text, no image, nothing ...

I know its friday, but ... I hate it when someone shows only a part of the code and not everything ...

Any info is appreciated!
Adrian


Frederik Soete
 

Hi there,

TGIF.

Not at all sure where you are going with that example, but you should know that "Controls" can be a member variable in e.g. a Form (window). You can identify or get a pre-existing Form via its (window/win32) handle, which you could get via Magic functions... Look those up in Magic help: handles exist for windows and controls. Actually a window is also kind of like a control... You can get a control through .Net Control.fromHandle(...). IIRC, you can assign and "cast" this value to a (Form) variable. Once you have a Form, you can access its Controls collection as needed.

This is all just to give you ideas to look up, not fleshed out, but I hope you get sth. from this regardlessly...

HTH,

Frederik Soete

Op vr 17 jun. 2022 18:24 schreef Adrian Wick <adrian.wick2015@...>:

Dear wizards.

can someone, for the love of God, explain to me how to code 3rd line of the following code in xpa (Controls.Add(simpleButton)).

private void CreateSimpleButton(int left, int top) { SimpleButton simpleButton = new SimpleButton(); Controls.Add(simpleButton); simpleButton.Text = "Show Settings Page"; simpleButton.ImageOptions.ImageList = imageCollection1; simpleButton.ImageOptions.ImageIndex = 0; simpleButton.Padding = new Padding(10); simpleButton.AutoSize = true; simpleButton.Location = new Point(left, top); simpleButton.Click += SimpleButton_Click; }

To me it looks like i need a Controls dotnet variable and add this button to the Controls. The button is on my form, but it has no text, no image, nothing ...

I know its friday, but ... I hate it when someone shows only a part of the code and not everything ...

Any info is appreciated!
Adrian


Keith Canniff
 

Adrian,

 

Is there any particular reason you’re trying to create a dotnet button rather than using a button style already built into XPA?

Might be going through extra work for no reason. A regular XPA button can raise an event that can call a dotnet system function.

 

Keith

 

From: main@magicu-l.groups.io <main@magicu-l.groups.io> On Behalf Of Adrian Wick
Sent: Friday, June 17, 2022 12:25 PM
To: main@magicu-l.groups.io
Subject: [magicu-l] DOT.NET code again #xpa

 

Dear wizards.

can someone, for the love of God, explain to me how to code 3rd line of the following code in xpa (Controls.Add(simpleButton)).

private void CreateSimpleButton(int left, int top) { SimpleButton simpleButton = new SimpleButton(); Controls.Add(simpleButton); simpleButton.Text = "Show Settings Page"; simpleButton.ImageOptions.ImageList = imageCollection1; simpleButton.ImageOptions.ImageIndex = 0; simpleButton.Padding = new Padding(10); simpleButton.AutoSize = true; simpleButton.Location = new Point(left, top); simpleButton.Click += SimpleButton_Click; }

To me it looks like i need a Controls dotnet variable and add this button to the Controls. The button is on my form, but it has no text, no image, nothing ...

I know its friday, but ... I hate it when someone shows only a part of the code and not everything ...

Any info is appreciated!
Adrian


Adrian Wick
 

@Frederik

thank you!

@Keith

no particular reason ... just trying to learn DOT.NET ... 

Regards
A


Adrian Wick
 

Found the solution in "3rd party dotnet samples".

Thank you!


Adrian Wick
 
Edited

I really don't know what i was doing before that it didn't work ...

3 simple lines of code are all that are needed and a dot.net variable.

  1. DNSet(D.Text,'Test')
  2. DNSet(D.Image,DotNet.System.Drawing.Image.FromFile('Image.png'))
  3. DNSet(D.AllowFocus,'FALSE'LOG)
and than an event for D variable and "Click" action to do something when the button is clicked ...

You guys just made my vikend :)

Beer's on me!
A


Craig Martin
 

Vikend? You sound like you are channeling Pavel Chekov in Star Trek IV: The Voyage Home

"Excuse me, sir. Can you direct me to the Navy base in Alameda? It's where they keep the nuclear wessels"

Anyhoo.

The dot net snippets feature has limitations that will inflict undue pain on your future.

Best to build a dotnet exe or dll (better, a python script or python compiled exe) independent of Magic  you can call.

This is not a "choose your own adventure" narrative. Thank me later.



From: main@magicu-l.groups.io <main@magicu-l.groups.io> on behalf of Adrian Wick <adrian.wick2015@...>
Sent: Friday, June 17, 2022 11:02 PM
To: main@magicu-l.groups.io <main@magicu-l.groups.io>
Subject: Re: [magicu-l] DOT.NET code again #xpa
 

[Edited Message Follows]

I really don't know what i was doing before that it didn't work ...

3 simple lines of code are all that are needed and a dot.net variable.

  1. DNSet(D.Text,'Test')
  2. DNSet(D.Image,DotNet.System.Drawing.Image.FromFile('Image.png'))
  3. DNSet(D.AllowFocus,'FALSE'LOG)
and than an event for D variable and "Click" action to do something when the button is clicked ...

You guys just made my vikend :)

Beer's on me!
A