Best way to show a picture in an X# VOForm

This forum is meant for questions and discussions about the X# language and tools
User avatar
Chris
Posts: 4584
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Best way to show a picture in an X# VOForm

Post by Chris »

Hi Dick,

Thanks, but I'm afraid just seeing what you do won't be enough, after all it's just a double click, not much can go wrong about itself :)
We would need to install debugging tools to find what's the problem in this particular case, but I think that's really overkill for debugging an empty window that you do not need anyway. In case you do get this anytime again, please let us know though!

.
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
ic2
Posts: 1804
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Best way to show a picture in an X# VOForm

Post by ic2 »

Hello Chris,

I add my remark in a issue I posted today here too, for future readers:

I reinstalled 2.10c and now the VO Form designer opened normally. Also on Frank's sample. I think the betaversion I still had installed may have been the cause of the FormDesigner not opening.

Dick
ic2
Posts: 1804
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Best way to show a picture in an X# VOForm

Post by ic2 »

Hello Chris,
Chris wrote: About the toolbox, you can choose to add a CustomControl to the window (from the VO toolbox), make it as large as you want and position it accordingly on the window, and then when you use SetParent(), use the handle of that custom control, instead of the handle of the window. That should do the trick.
.
In Frank's sample program with the Winforms control on it, the PostInit says:

Code: Select all

SetParent(Self:pictureBox1:Handle, Self:Handle())
When I add a Customcontrol in the VO style Window editor, change the name to PICT and change the above line to:

Code: Select all

SetParent(self:oDCPict:Handle())
I get a compiler as error 1 below and with

Code: Select all

SetParent(Self:pictureBox1:Handle, Self:oDCPict:Handle())
I get a runtime error 2).

What parameter(s) am I suppose to add? Or should I do something else?

1 Severity Code Description Project File Line Suppression State
Error XS7036 There is no argument given that corresponds to the required formal parameter 'hWndNewParent' of 'VOWin32APILibrary.Functions.SetParent(PTR, PTR)' VOMDIApp2 C:TempVOMDIApp2Window1.prg 51

2 System.NullReferenceException: Object reference not set to an instance of an object.

Dick
User avatar
Chris
Posts: 4584
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Best way to show a picture in an X# VOForm

Post by Chris »

Hi Dick,

SetParent() needs 2 arguments, first the handle of the control you need to move and second the handle of the parent, so your (2) version is the correct one.

It's very strange if you are getting a NullReferenceException with it, are you sure it happens in this line of code and not sometime later in the program? Try checking the SELF:oDCPict object before using SetParent(), is it indeed NULL?

.
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
ic2
Posts: 1804
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Best way to show a picture in an X# VOForm

Post by ic2 »

Hello Chris,

It is not so strange, I realize now. I out commented some of the existing lines including the instantiation. So the error makes sense ;)

When I replace the SetParent line with SetParent(Self:pictureBox1:Handle, Self:oDCPict:Handle())
the program uses the CustomControl which I added in the form editor.

I am still wondering if that is the most efficient way? I can't do something like this:

Self:oDCPict:= System.Windows.Forms.PictureBox{} (XS0029, implicit conversion of PictureBox to VO.Custom.Control) and all the other assignments are not of that CustomCOntrol class. But the (working) code feels a bit contrived:

Code: Select all

Self:pictureBox1:= System.Windows.Forms.PictureBox{}
Self:pictureBox1:Location := System.Drawing.Point{1, 1}
Self:pictureBox1:Name := "e""pictureEdit1"
Self:pictureBox1:Size := System.Drawing.Size{400, 400}
Self:pictureBox1:SizeMode:= System.Windows.Forms.PictureBoxSizeMode.Zoom
Self:pictureBox1:Visible := True
Self:pictureBox1:TabIndex := 700
Self:pictureBox1:Load("https://dt9qzg9h465rt.cloudfront.net/c:tempSomePict.jpg")	
SetParent(Self:pictureBox1:Handle, Self:oDCPict:Handle())		
Dick
User avatar
Chris
Posts: 4584
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Best way to show a picture in an X# VOForm

Post by Chris »

Hi Dick,

You can't assign a Windows.Forms control to a VO GUI control object, in the same way you cannot assign a WPF control to a WinForms object or vice versa. Or like assigning a VO style ragged array to a fixed size array, they are just different things.They are both controls that you can put on a window, but they have a completely different design and of course also different class hierarchy.

.
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
User avatar
Kees Bouw
Posts: 99
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Best way to show a picture in an X# VOForm

Post by Kees Bouw »

Hi,

I used code similar to the code below to show a .NET HTML editor control on a VO MDI datawindow with a custom control. I have also tried it in another app on a VO dialogwindow without the custom control. In both cases, everything works (you can type in the control, use the cursor keys and edit text) except for the ENTER key. This should produce a new line but seems to do nothing at all. I have written code to intercept key presses inside the control and the ENTER is not detected at all so I suspect the ENTER key is somehow not "passed on" to the control. The same control on a Winforms form works fine including the ENTER key. Can anyone think of a reason why specifically the ENTER key would not work on a VO window?

Thanks for any help!

Kees.
Frank Müßner wrote:Hello Dick,

I use this code when I need a .Netcontrol on a VO window.

Code: Select all

    self:pictureEdit1:= DevExpress.XtraEditors.PictureEdit{}
    self:pictureEdit1:Location := System.Drawing.Point{self:size:Width-175, 124} //tt:Height-289}
    self:pictureEdit1:Name := "e""pictureEdit1"
    self:pictureEdit1:Properties:SizeMode := DevExpress.XtraEditors.Controls.PictureSizeMode.Zoom
    self:pictureEdit1:Properties:BorderStyle := DevExpress.XtraEditors.Controls.BorderStyles.NoBorder
    self:pictureEdit1:Properties:ShowMenu := false
    self:pictureEdit1:Size := System.Drawing.Size{162, 162}
    self:pictureEdit1:Visible := True
    self:pictureEdit1:TabIndex := 500
    SetParent(SELF:pictureEdit1:Handle, self:Handle())
runs without problems until now.

Maybe it will help you

Frank
User avatar
Chris
Posts: 4584
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Best way to show a picture in an X# VOForm

Post by Chris »

Hi Kees,

Try adding this code to your app:

Code: Select all

USING System.Collections.Generic
GLOBAL gaHandlesForEnter := List<IntPtr>{} AS List<IntPtr>

// put this method inside the App subclass in your code
METHOD BeforeDispatch(hWnd,uMsg,wParam,lParam)
	IF uMsg == WM_KEYDOWN .and. wParam == VK_RETURN
		IF gaHandlesForEnter:Contains((IntPtr)hWnd)
			SendMessage(hWnd, WM_CHAR , 10 , 0)
			SendMessage(hWnd, WM_CHAR , 13 , 0)
			RETURN FALSE
		END IF
	ENDIF
RETURN TRUE
Now, after you put any .Net control to a VO window (with SetParent()), add this code exactly after SetParent():

Code: Select all

gaHandlesForEnter:Add(oMyNetControl:Handle)
Does it work ok now?

.
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
User avatar
Kees Bouw
Posts: 99
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Best way to show a picture in an X# VOForm

Post by Kees Bouw »

Hi Chris,

Thank you for the code. I have tried it but unfortunately it makes no difference. I have also put a MessageBox below the line "IF uMsg == WM_KEYDOWN .and. wParam == VK_RETURN" and it does not appear if I press Enter so I guess the ENTER key does not even make it to that point.

Kees.
User avatar
Chris
Posts: 4584
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Best way to show a picture in an X# VOForm

Post by Chris »

Hi Kees,

Can you please send me a complete zipped sample solution showing the not working correctly control on the VOWindow?
I do have the devexpress controls, so no need to send those dlls also.

.
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
Post Reply