6/7/2025 5:21:35 AM
|
|
slxdeveloper.com Community Forums |
|
|
|
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
Forum to discuss the use of .NET Extensions in SalesLogix version 7 and higher. View the code of conduct for posting guidelines.
|
|
|
|
Resize a .Net View
Posted: 15 Nov 07 8:17 AM
|
Hi,
I made .Net Usercontrol (according to the .Net Account Detail View from Sage SDK Samples) but I want that the Control fills the View. How can I set the Height and Width of my Usercontrol so that it always fills out the SLX View even when it's resized?
Joern |
|
|
|
Re: Resize a .Net View
Posted: 15 Nov 07 8:37 AM
|
I have an example of that in the sample code and screencast here: http://www.slxdeveloper.com/page.aspx?action=viewarticle&articleid=91
Basically, I like to declare my RECT like this:
[Serializable, StructLayout(LayoutKind.Sequential)] public struct RECT { public RECT(int left, int top, int right, int bottom) { Left = left; Top = top; Right = right; Bottom = bottom; } public int Left; public int Top; public int Right; public int Bottom; public int Height { get { return Bottom - Top; } } public int Width { get { return Right - Left; } } public Size Size { get { return new Size(Width, Height); } } }
So it has built in Height, Width and Size properties. Then for my UserControl, I use the HWND of the parent (where I am embedding it) and call the Win32Api GetWindowRect to get a RECT for the parent container (using the struct above). Then I just set the Size of the UserControl from the Size of the parent area returned in the RECT from GetWindowRect. Something like this:
//hwnd is the handle of the parent container RECT rect; if (GetWindowRect(hwnd, out rect)) { MyUserControl.Size = rect.Size; }
Make sense? Also, don't forget to add the DllImport for GetWindowRect.
using System.Runtime.InteropServices; //... [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
-Ryan |
|
|
|
Re: Resize a .Net View
Posted: 15 Nov 07 10:03 AM
|
Ok thanks a lot, it works now. One more Question. How can I react in my Usercontrol on the resize event of the parent (SLX) view?
Joern |
|
|
|
Re: Resize a .Net View
Posted: 17 Nov 07 3:57 PM
|
A way that I have done this is to declare my usercontrol as com visible (just like Ryan told you to) then in the Run function of your extension do a "return this" so that when you execute your extension you get a pointer back to the form. Save that pointer to a global var in your script and just call the resize method in your parent forms resize event. Here is an example that extends Ryans example.
in the extension: public object Run(object[] Args) { return this; }
public void RefreshSize(IntPtr parent) { Win32.RECT rect; Win32.GetWindowRect(parent, out rect); this.Size = rect.Size; }
then from the slx form
Dim ext ' this variable will hold the handle for the loaded .NET Extension Dim frm 'this varuable will hold the actual form
public Sub SupportAXFormChange(Sender) 'if we have already created one then we close it and create another one If ext = "" Then ext = Application.Managed.Create("Extensions", "Extensions.CustomControl") End If
'launch the .net customization Set frm = Application.Managed.Run(ext, Form.HWND) End Sub
Sub SupportAXFormResize(Sender) if ext <> "" then frm.RefreshSize Form.HWND end if End Sub
Hope that is helpful. |
|
|
|
Re: Resize a .Net View
Posted: 18 Dec 07 6:44 AM
|
What I do is add a method to my .net control called SetSize(x,y, width,height) and just call that from the appropiate size event. Since the control at that point is already sited onto its host I do not have to worry abount HWNDs.
Inside my method I then call
this.Bounds = new Rectangle(x,y,width,height);
Mark |
|
|
|
Re: Resize a .Net View
Posted: 19 Dec 07 9:45 AM
|
That is good to know. I guess I was doing a little overkill. Thanks. |
|
|
|
You can
subscribe to receive a daily forum digest in your
user profile. View the site code
of conduct for posting guidelines.
Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
|
|
|
|
|
|
|
|