I have 2 forms, 1 is for control and the other is for display. Its 2 because the 1 for display will consume the whole screen and there's no space for buttons.
Im trying to control form4 using form2 or some other form, navigating a certain webpage in the process.
I have this code for the control:
but it does not work, what would I do?
Form4.WebBrowser1.Navigate("http://www.animedreaming.com/fairy-tail-episode-19/")
If I get your meaning you can access one form from another by making a local class along the lines of...
FORM#1 -->
Public Class FORM#1
Inherits System.Windows.Forms.Form
Public Shared Form as FORM#1
Public Sub someAction (byVal someParameter as someKindOfThingy)
' do something
End Sub
End Class
FORM #2 -->
FORM#1.someAction(someParameter)
===================================
There are any number of variations on this basic theme... from declaring a local class in FORM#2 as type FORM#1 through the use of delegates.
Related
I have found that navigation between pages in VB.NET is called like this:
Frame.Navigate(GetType(MainPage))
and from what I have read, you can pass a parameter like this:
Frame.Navigate(GetType(MainPage), "Parameter Here!!")
The problem is, I cannot get it through to the other page. Finding many examples in C# I see it might be using one of the below methods. Although, none of these seem to be recognised in VS2015
Protected Overrides Sub LoadState(navigationParameter As Object, pageState As Dictionary(Of String, Object))
Protected Overrides Sub onNavigateTo(**Params**)
^^ They both state "...does not have an override a sub in a base class"
How to I receive the parameter in the newly presented page? is it a different method entirely?
After digging into the Page class which all pages inherit from It seems overriding the "onNavigateTo" Sub is key in this operation. From here you can access its argument and pass through successfully.
Unfortunaly, even Microsoft doesn't provide VB.NET Documentation for this. Here is my code:
In the First page
Frame.Navigate(GetType(BlankPage1), "Hello")
In the Second Page
Public NotInheritable Class BlankPage1
Inherits Page
Public thestring As String
Protected Overrides Sub onNavigatedTo(e As NavigationEventArgs)
thestring = e.Parameter
End Sub
This works successfully. I hope this helps people in the future
I have a windows form [myForm] within a VSTO addin project - currently when I .Show() this form it is displayed outside the Excel application (on another monitor in my case), but I would like it to be displayed as an MdiChild of the Excel application hosting it, so within the main Excel application window.
myForm x = new myForm;
x.Show();
There is an overload of Show() that accepts an owner argument of type System.Windows.Forms.IWin32Window, but I'm not sure if that is how one might do this?
There is also an MdiParent property of the form, which is of type System.Windows.Forms.Form type, but in this case I want the parent to be the Excel application, not another windows form.
The Hwnd property of the Window class returns an integer which stands for the window handle. But the Show method accepts an instance of the IWin32Window interface which exposes Win32 HWND handles. To get an instance of the interface you need to declare a class which implements that interface.
public class WindowImplementation : System.Windows.Forms.IWin32Window
{
public WindowImplementation(IntPtr handle)
{
_hwnd = handle;
}
public IntPtr Handle
{
get
{
return _hwnd;
}
}
private IntPtr _hwnd;
}
Then you can use the following code to get form shown specifying the parent Excel window handle.
form1.Show(new WindowImplementation(excelWindow.Hwnd));
After breaking down all possible causes of the issue, I have arrived with the following situation. I have a custom user control containing a panel and a control (button, label etc...) within this panel. I have also created public read only properties for the panel as well as the child control of the panel. Each of these properties has their DesignerSerializationVisibility attribute set to Content. When configured this way no code is serialized for the child control of the panel when the custom user control is used on a form. Upon building the control, the child control either disappears or experiences an incomplete rendering at design-time. If I change either the panel or its child control’s DesignerSerializationVisibility to visible, everything serializes and renders correctly. However, this then prevents me from being able to provide the end user with the ability to adjust either the panel or child controls property values. This one truly has me stumped!
UPDATE:
After getting home and performing the same steps on my development VM (also a fresh installation of VS2013) there are no issues. I am very confused at why this issue would be occurring on my work computer and not another. Any ideas are greatly appreciated as the mystery deepens...
Public Class ExampleUserControl
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
<Browsable(True), _
EditorBrowsable(EditorBrowsableState.Always), _
Category("Appearance"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
Public ReadOnly Property LeftPanel As Panel
Get
Return Me.ExampleLeftPanel
End Get
End Property
<Browsable(True), _
EditorBrowsable(EditorBrowsableState.Always), _
Category("Control"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
Public ReadOnly Property LeftPanelButton As Button
Get
Return Me.ExampleLeftButton
End Get
End Property
<Browsable(True), _
EditorBrowsable(EditorBrowsableState.Always), _
Category("Appearance"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
Public ReadOnly Property RightPanel As Panel
Get
Return Me.ExampleRightPanel
End Get
End Property
<Browsable(True), _
EditorBrowsable(EditorBrowsableState.Always), _
Category("Control"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
Public ReadOnly Property RightPanelButton As Button
Get
Return Me.ExampleRightButton
End Get
End Property
End Class
I'm still not sure why this issue was occurring. However, after moving the custom user control into my control library (a separate .dll), all is working as expected. I suspect it was a glitch in the timing when compiling. Possibly it was trying to build the controls and serialize the code at the same time.
I have the following lines of code as a test user control. When the project is built, and I drag this user control onto a form, I get an error dialogue to the effect that EF can't find the connection string for the context. Yet when I use the same variable in a form, all is well. It seems the user control is using a different context within which to look for the connection string than the usual app.config.
Public Class InvoiceWorkOrderSearch
Private _dataHelper As WorkOrderData = New WorkOrderData()
End Class
During Design time?
You can avoid this be only instancing the object if the control is in runtime mode.
The build in property to check for desing time (Me.DesignMode) is poor since it only tells you if you are currently designing the control itself. It returs false if you drop the usercontrol on a form.
You can use this code to check for designtime: http://dotnet-snippets.de/dns/designmode-workaround-windows-forms-SID299.aspx
Public Class InvoiceWorkOrderSearch
Private _dataHelper As WorkOrderData
Public Sub New()
If IsDesignMode(me) = False Then
_dataHelper = New WorkOrderData()
End If
End Sub()
End Class
I'm trying to create a control (Parent Class) that uses a custom grid (Child Class). The grid has a series of constructors and methods for populating itself based on property values in the [parent] control.
The only way I found to make these property values available to the grid is by making them Shared but that's causing me all kinds of issues.
REQUIREMENTS
Properties in the control (parent) must be accessible to the grid (child).
Properties in the control must be visible in the design-time properties explorer.
The grid class must only be instantiable by the parent class.
As a side note: please indicate if your answer will allow me to share properties/methods back and forth between child and parent. That would be nice, but just a bonus.
Thanks ;)
EDIT - A VERY simple example based on my situation:
Partial Public Class catContent
Inherits System.Web.UI.UserControl
Protected Sub Page_Load(sender, e) Handles Me.Load
Page.Controls.Add(New CategoryResultGrid(category))
End Sub
Private Shared _product As String = String.Empty
Shared Property Product() As String
Get
Return _product
End Get
Set(ByVal value As String)
_product = value.Trim()
End Set
End Property
Private Class CategoryResultGrid
Inherits GridView
Sub New(ByVal category As String)
'How do I access "Product" here without sharing it?
End Sub
End Class
End Class
Do NOT use shared, it will break your app as soon as you put more than one of you custom control in your app.
If you only want the Grid to exist in the context of the Parent control, then consider exposing it similar to how the ListView control exposes its Items collection.
If you want your Grid to access fields in the (parent) Control there are several ways to do that. You could pass an instance of the Parent to the Grid, you can let the Grid use the standard Control methods to get its parent reference, or you can implement the Grid as an inner class of the Parent.