I have 3 user controls and a main form and I can reference the user controls and use methods from the main form just fine:
Dim ReviewPanel As New ReviewPanel
Controls.Add(ReviewPanel)
ReviewPanel.BringToFront()
ReviewPanel.Go(-8, 0)
But referencing from the user control to the main form doesn't work properly:
Private Sub SelectionPanelClick(sender As Object, e As EventArgs) Handles MyBase.Click, picCover.Click, lblTitle.Click
Dim _Main As New Form1
_Main.DisplayReview()
End Sub
The code still runs fine; I can add messageboxes in the main form method and they'll still show up. However, nothing visually happens like a label won't update with the username.
I've tried to solve it and find workarounds but nothing is working.
Use the ParentForm() property and cast it to Form1:
' ... in your UserControl ...
Dim frm As Form = Me.ParentForm
If Not IsNothing(frm) AndAlso TypeOf frm Is Form1 Then
Dim f1 As Form1 = DirectCast(frm, Form1)
f1.DisplayReview()
End If
Related
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
For i As Integer = 0 To 4
Me.Hide()
Form2.Show()
i = i + 1
Next
End Sub
'This is my code with problem
I used for loop but the form2 only appears once so i have to keep pressing the button
It sounds like what you want is 4 different instances of your form to appear. (After all, the same form can't "appear 4 times" because once it's already visible, it's already visiblt.) For that you'd need 4 instances of your form. Something like this:
Private form2Instances As New List(Of Form2)
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
For i As Integer = 0 To 4
Dim form2 As New Form2()
form2Instances.Add(form2)
form2.Show()
i = i + 1
Next
Me.Hide()
End Sub
The idea here is that your class is maintaining a collection of Form2 instances, and click your button essentially does a few things:
Populates that collection with those instances. (As it's assumed that you'll want to reference them later, outside the scope of this click handler.)
Shows each of those instances.
Hides the current form (which only needs to happen once, outside the loop).
I'm in the process of converting some outlook VBA macros to an Add-in. I am having difficulty with my macros that create emails based on a template. I decided to code a simple button to create and display a new email with the subject test.
Everything is working up to displaying the email which doesn't happen.
Private Sub ButtonGenEmail_Click(sender As Object, e As EventArgs) Handles ButtonGenEmail.Click
Me.Close()
Dim objApp As Outlook.Application
Dim objMail As Outlook.MailItem
objApp = Globals.ThisAddIn.Application
objMail = objApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
objMail.Subject = "test"
objMail.Save()
objMail.Display(False)
End Sub
At one point I added msgbox "Done" after objMail.Display(False) and the message never appears.
Thanks in advance
This should obviously work. I'm not so skilled in Outlook but I guess the problem here is that you run it from a form (I see the Me.Close)
Isn't then Outlook blocking to display the mail because the form is still open (I guess modal = ShowDialog())?
I think you will have to either change the form to be not modal (use Show() instead of ShowDialog()) or handle the event after the form is closed, something like
All code below written from top of my mind, so I may miss something
A method from where you initialize the form
Dim frm as new YourForm()
frm.ShowDialog()
if frm.MyState = TheyClickOnButton Then
' Run your mailItem code here
End If
in the form code
Public Enum State
Unknown = 0
TheyClickedOnButton
End Enum
Public Property MyState as State
Private Sub ButtonGenEmail_Click(sender As Object, e As EventArgs) Handles ButtonGenEmail.Click
MyState = TheyClickedOnButton
Me.Close()
End Sub
I am new here. So apologize in advance if not wording question properly.
I am developing an application (VS2013, Visual Basic) that using multiple menu items in the MenuStrip. When item is clicked the identical function is called - the Tab is created and appropriate form is loaded.
i.e.
Private Sub XXXMNU0039_Click(sender As Object, e As EventArgs) Handles XXXMNU0039.Click
Dim f1 As New frm_B05_01_SalesQuotes
Dim imgnm As String = "XXXMNU0039"
Call XXXTabPages("Sales Quotes", f1, imgnm)
End Sub
Private Sub XXXMNU0040_Click(sender As Object, e As EventArgs) Handles XXXMNU0040.Click
Dim f1 As New frm_B05_03_SalesQuotesReports
Dim imgnm As String = "XXXMNU_Reports"
Call XXXTabPages("Sales Quotes Reports", f1, imgnm)
End Sub
....
I am wondering is there is a way to create a "global" default "on click event" for all menu items that will accomplish the same thing by default. I have all the relevant information for each menu item stored in a table and hope to avoid creating "on click" for each item.
Thanks in advance.
You could have the same handler for the click event of your ToolStripMenuItems.
Just add, after the first Handles XXXMNU0039.Click the event to handle for another ToolStripMenuItem and so on
Oviously, then problem is how to differentiate the various ToolStripMenuItem that calls the same event handler. But in the event arguments there is the Sender object that represent the current ToolStripMenuItem that has called the event.
Just DirectCast to a ToolStripMenuItem and read its name to pass the correct parameter to the XXXTablPages method
Private Sub menuItemHandler_Click(sender As Object, e As EventArgs) _
Handles XXXMNU0039.Click, XXXMNU0040.Click
Dim f1 As New frm_B05_01_SalesQuotes
Dim itm = DirectCast(sender, ToolStripMenuItem)
Dim imgnm As String = item.Name
Call XXXTabPages("Sales Quotes", f1, imgnm)
End Sub
I use several instances (myForm1, myForm2,etc...) of the same MDIChild form (frmChart) to display different MSCharts:
frmMain:
Private Sub Open()
dim myForm1 as frmChart
myForm1.Show
dim myForm2 as frmChart
myForm2.Show
End sub
The problem happens when I try to save the MSChart of one opened instance, because I call a frmChart.SaveChart() function which resizes a picturebox and then the Form_Load() event is invoked, so a new extra frmChart is opened.
frmChart:
Public Sub SaveChart()
picGrapgh.Height = chChart.Height
picGrapgh.Width = chChart.Width
picGraph.Autoredraw = True
picGraph.Picture = picGraph.Image
SavePicture picGraph.picture, FileName
End Sub
When I call that sub, it invokes the Form_Load() of the frmChart. This only happens when I use form instances (myForm1). Once I use any property of the PictureBox control of the frmChart it launches the Form_Load event. How could I prevent it?.
Thank you very much in advance.
Regards,
Ruben
There are 2 problems:
dim myForm1 as frmChart
This just declares that myForm1 will be of the Type frmChart if/when one is created (instanced). To create an actual instance of frmChart:
dim myForm1 as New frmChart
Since myFormN is now an instance of frmChart, you can call those procedures directly on/thru the instance variable:
myForm1.SaveChart
I'm trying to page and sort my DataGrid which is inside a ModalPopupExtender but I can't page it in any way, already tried with <Triggers>, put the UpdatePanel inside, outside, in the middle, and it does NOT work. Modal popup does not get closed but the grid just disappears. Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
BindData()
End If
End Sub
Private Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
SqlServerDS.SelectCommand = "SELECT * FROM emp WHERE name LIKE '%" & txtSearchName.Text & "%'"
BindData()
End Sub
Private Sub BindData()
grdSearch.DataSource = SqlServerDS
grdSearch.DataBind()
End Sub
Private Sub grdBuscaPaciente_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles grdSearch.PageIndexChanging
grdSearch.PageIndex = e.NewPageIndex
BindData()
End Sub
Inside the Designer, this is the code h:
<modalpopupextender>
</modalpopupextender>
<panel>
<updatepanel>
<gridview>
</gridview>
</updatepanel>
</panel>
Tommy is right, so what you just have to do is re-show the popup.
After the BindData() in the PageIndexChanging event show the panel again with the Show() method of the popup extender.
This code is in c# but is pretty much the same.
gvHorarioPB.DataSource = (DataTable)Session["Prueba"];
gvHorarioPB.PageIndex = e.NewPageIndex;
gvHorarioPB.DataBind();
//mpePB is my modalpopupextender
this.mpePB.Show();
If you are using the .NET AJAX toolkit, keep in mind that each time you click someting (paging, sorting, etc.), the page performs a postback, even if it looks AJAX-y. Meaning that you will need to rebind the data each time. Try removing the IfPostback in your page load and see what that does for you.