Microsoft Visual Studio 2012 using Visual Basic, how to correctly write in code? - vb.net

Currently I'm new to this and I'm attempting to get this all to work, right now I've looked into and made a module which allows to me to change the user-agent of the internal web-browser so I can manipulate it easily however this is where the issue lies.
I'm assuming I must be editing the auto generated code because the file itself is called "Form1.Designer.vb" and I have no idea where to start putting in custom code to override the current code such as I wanting to do something like this;
Me.WebSiteBrowser1.Dock = System.Windows.Forms.DockStyle.Fill
Me.WebSiteBrowser1.Location = New System.Drawing.Point(3, 3)
Me.WebSiteBrowser1.MinimumSize = New System.Drawing.Size(20, 20)
Me.WebSiteBrowser1.Name = "WebSiteBrowser1"
Me.WebSiteBrowser1.Size = New System.Drawing.Size(671, 413)
Me.WebSiteBrowser1.TabIndex = 0
ChangeUserAgent("This is after the url agent gets changed after the first url open")
Me.WebSiteBrowser1.Navigate("http://www.whatsmyuseragent.com/", Nothing, Nothing, "User-Agent: This is the first open url agent")
However whenever I change anything in the visual template it automatically resets back to
Me.WebSiteBrowser1.Dock = System.Windows.Forms.DockStyle.Fill
Me.WebSiteBrowser1.Location = New System.Drawing.Point(3, 3)
Me.WebSiteBrowser1.MinimumSize = New System.Drawing.Size(20, 20)
Me.WebSiteBrowser1.Name = "WebSiteBrowser1"
Me.WebSiteBrowser1.Size = New System.Drawing.Size(671, 413)
Me.WebSiteBrowser1.TabIndex = 0
So my question is where do I write the custom code that would allow me to keep that after the auto-generation from the visual creator?

You should be putting your code in the form1.vb and leave the designer file alone. In the form1.vb[Design] you can change the properties in the properties window. If it is not currently docked to the right side of the VS designer you can show it by going to the Menu -> View -> Properties Window and select it.

Related

Positioning of a menu item image (hbmpItem of a MENUITEMINFO) in a context menu

I am inserting a menu item into an Outlook Context menu for a subject text control. Here you can find a previous question I had on doing this.
The issue I have is that the image of the menu item is positioned strangely in Outlook 2010. In Outlook 2007 it is positioned differently. It seems that the menu item is holding the position for the checked image free in Outlook 2010.
This shows how my menu item looks with the below code. Notice the large space to the left of the image.
This shows how it looks when i add the MIIM_CHECKMARKS flag to fMask and a bitmap to the hbmpUnchecked pointer.
Dim bmp As Drawing.Bitmap = My.Resources.olContextMenuIcon
bmp.MakeTransparent(bmp.GetPixel(10, 10))
hbitmap = bmp.GetHbitmap
Dim mii As New NativeMethodsEX.MENUITEMINFO
With mii
.cbSize = Marshal.SizeOf(mii)
.fMask = NativeMethodsEX.MIIM.MIIM_BITMAP Or NativeMethodsEX.MIIM.MIIM_STRING Or NativeMethodsEX.MIIM.MIIM_FTYPE Or NativeMethodsEX.MIIM.MIIM_STATE Or NativeMethodsEX.MIIM.MIIM_ID
.wID = WM_APP
.fType = NativeMethodsEX.MFT.MFT_STRING
.dwTypeData = String.Concat("Wrong Position")
.fState = NativeMethodsEX.MFS.MFS_ENABLED
.hbmpItem = hbitmap
End With
If ShowTop Then
NativeMethodsEX.InsertMenuItem(aHwnd, 0, True, mii)
NativeMethodsEX.InsertMenu(aHwnd, 1, NativeMethodsEX.MFT.MFT_BYPOSITION Or NativeMethodsEX.MFT.MFT_SEPARATOR, Nothing, Nothing)
Else
Dim menuItemCount As Integer = NativeMethodsEX.GetMenuItemCount(aHwnd)
NativeMethodsEX.InsertMenu(aHwnd, menuItemCount, NativeMethodsEX.MFT.MFT_BYPOSITION Or NativeMethodsEX.MFT.MFT_SEPARATOR, Nothing, Nothing)
NativeMethodsEX.InsertMenuItem(aHwnd, menuItemCount + 1, True, mii)
End If
NativeMethodsEX.DrawMenuBar(subjectRegionHwnd)
So how can I tell the menu item not to reserve the space for the check / uncheck image?
I have two answers to this problem.
I indicated above that the issue existed on an menu in Outlook 2010 but not in Outlook 2007. This is not true. These office versions are of course on different computers and it was a display setting in windows that was the cause of the problem. The above menu is what you get when you have the setting "Use Visual Styles on Windows and buttons" in Performance Options > Visual Effects turned off (Win 7). If you enable this setting then the menus look and especially act very differently.
But what if a user disables this setting how can you deal with it (Not sure if this is relevant for Win10).
You need to set the menu style through the use of the Menuinfo in particular you need to set the flag MNS_NOCHECK. Then the space is gone as the menu no longer is expecting the check marks.
This solution can also be seen here in another stackoverflow answer.

Add Image to Custom Task Pane Title in Outlook - VB.Net

I have created a custom task pane in VB.Net for Outlook using the Code given below and I would like to add more content to the header (image and a button) of the User Control instead of just the title. Is there a way I can achieve this?
myUserControl1 = New OutlookTaskPane
myUserControl1.TabStop = True
Dim width As Integer = myUserControl1.Width
myCustomTaskPane = Me.CustomTaskPanes.Add(myUserControl1, "My Custom Task Pane")
myCustomTaskPane.Width = width
myCustomTaskPane.Visible = True
myCustomTaskPane.DockPositionRestrict = Microsoft.Office.Core.MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoChange
Let me know if there is any other way of achieving this please.
Thanks.
Unfortunately the TaskPane header is not customizable. Only Add-in Express supports similar customizations using their implementation of Advanced Form Regions (although only the header icon and header color can be changed and you can't add Windows Forms controls to it). Another option is to implement your own type of Task Pane so you have complete control over the UI; see https://code.msdn.microsoft.com/OlAdjacentWindows/.

Accessing custom task pane in active window - Visual Basic, VSTO

I'm creating a COM add-in in VSTO for Ppt 2013 and am having a problem referencing the custom task pane in the active window.
My code is supposed to make the custom task pane visible for the active window only, however it currently runs for all document windows.
My code is:
For Each CTP As Microsoft.Office.Tools.CustomTaskPane In Globals.ThisAddIn.CustomTaskPanes
If CTP.Window Is Globals.ThisAddIn.Application.ActiveWindow Then
CTP.Visible = True
End If
Next
The taskpane is added to each new presentation created/ opened using the below code
AddIn_control1 = New AddIn_control
AddIn_taskpane = Me.CustomTaskPanes.add(AddIn_control1, "Add-in taskpane", Me.Application.ActiveWindow)
I conducted a little experiment and turns out CustomTaskPane.Window is always ActiveWindow. So to workaround it you can keep tracking of tackpanes in some dictionary:
Dictionary<CustomTaskPane, PowerPoint.Presentation> ctpDict = new Dictionary<CustomTaskPane, PowerPoint.Presentation>();
void Application_AfterNewPresentation(PowerPoint.Presentation Pres) {
AddIn_control AddIn_control1 = new AddIn_control();
CustomTaskPane AddIn_taskpane = this.CustomTaskPanes.Add(AddIn_control1, "Add-In Taskpane", this.Application.ActiveWindow);
ctpDict.Add(AddIn_taskpane, Pres);
}
and later you can use it:
if (cptDict[CTP] == Globals.ThisAddIn.Application.ActivePresentation) {
CTP.Visible = true;
}

VB.NET VSTO referencing custom task panes from ribbon in multiple windows PowerPoint 2013 [duplicate]

I'm creating a COM add-in in VSTO for Ppt 2013 and am having a problem referencing the custom task pane in the active window.
My code is supposed to make the custom task pane visible for the active window only, however it currently runs for all document windows.
My code is:
For Each CTP As Microsoft.Office.Tools.CustomTaskPane In Globals.ThisAddIn.CustomTaskPanes
If CTP.Window Is Globals.ThisAddIn.Application.ActiveWindow Then
CTP.Visible = True
End If
Next
The taskpane is added to each new presentation created/ opened using the below code
AddIn_control1 = New AddIn_control
AddIn_taskpane = Me.CustomTaskPanes.add(AddIn_control1, "Add-in taskpane", Me.Application.ActiveWindow)
I conducted a little experiment and turns out CustomTaskPane.Window is always ActiveWindow. So to workaround it you can keep tracking of tackpanes in some dictionary:
Dictionary<CustomTaskPane, PowerPoint.Presentation> ctpDict = new Dictionary<CustomTaskPane, PowerPoint.Presentation>();
void Application_AfterNewPresentation(PowerPoint.Presentation Pres) {
AddIn_control AddIn_control1 = new AddIn_control();
CustomTaskPane AddIn_taskpane = this.CustomTaskPanes.Add(AddIn_control1, "Add-In Taskpane", this.Application.ActiveWindow);
ctpDict.Add(AddIn_taskpane, Pres);
}
and later you can use it:
if (cptDict[CTP] == Globals.ThisAddIn.Application.ActivePresentation) {
CTP.Visible = true;
}

Associated icons blank in OpenFileDialog

I'm deploying an application built with VS 2010 Express edition via ClickOnce.
I have associated some file extensions using the options provided in the Publish section of the project's properties.
When I install the application, the associated file extension icons appear normally in Explorer but, when the user tries to open a file in my application, the associated icons appear blank.
The relative code section is the following:
Dim dialog As New OpenFileDialog
With dialog
.AddExtension = True
.CheckFileExists = True
.CheckPathExists = True
.DefaultExt = "pss"
.FileName = String.Empty
.Filter = "Data files|*.pss|All files (*.*)|*.*"
.FilterIndex = 0
.InitialDirectory = MySettings.SavePath
.Multiselect = False
.ValidateNames = True
If .ShowDialog(Me) = Windows.Forms.DialogResult.OK Then
OpenFile(.FileName)
End If
End With
I was always under the impression that OpenFileDialog is a wrapper for Explorer, but for some reason the icons don't appear correct.
Does anyone have any idea how to correct the problem?
Edit: The behaviour is only relevant to Windows 7. Windows XP behaves normally.
I believe you need to set the default view to thumbnail, so that the graphics appear for the pss files. You can check this by manually changing the view to thumbnail while running your application.
If changing the view to thumbnail shows the graphics then check the link below to achieve this:
http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/571b39c2-0edf-4159-ac8d-1c059f69a978
I forgot to change the included associated icons to:
Build action: Content
Copy to Output Directory: Always
I found this thanks to the manual updates, during which I was getting the error message "Object Reference not set to an instance of an object" during the updateCompleted event.