In the tray, multiple icons appear during the course of the program running. I'm not sure why. I currently have this code:
Public Sub ShowBalloonTip(ByVal Text As String, ByVal Title As String)
niMain.Visible = False
niMain.BalloonTipText = Text
niMain.BalloonTipTitle = Title
niMain.BalloonTipIcon = ToolTipIcon.Info
niMain.Visible = True
niMain.ShowBalloonTip(1000)
End Sub
And when the form is being closed, I set the object to not being visible.
What can I do to solve this?
Related
I am using Visual Studio 2022 and my language of choice is VB. When the program starts it creates Multiple Panels that are located in the same position created from data from a database.
No matter what I do, I can not get any of the panels to show. I can search for the panels and verify the panels exist, I can search the panels and verify that there are buttons in the panels. However I can not get each individual panel to show.
I am going to list all the panels that are created in the order they are created and they are all in the exact same position and size.
panel2
pnlDeptItems01
pnlDeptItems11
pnlDeptItems22
pnlDeptItems23
pnlDeptItems24
pnlDeptItems25
pnlDeptItems26
pnlDeptItems27
pnlDeptItems28
pnlDeptItems29
pnlDeptItems32
pnlDeptItems54
pnlDeptItems82
pnlDeptItems83
pnlDeptItems84
pnlDeptItems85
pnlDeptItems96
pnlDeptItems97
pnlDeptItems98
pnlDeptItems99
Visible and Enabled are set to true for all panels on creation.
Below is the code that I use to search for the panel by name and if I find it then try to make it visible which it already is and then I try to bring it to front. And it does absolutely nothing but keeps the 1st panel visible.
For Each control In Me.Controls.OfType(Of Panel)
If control.Name = btnPanelName Then
control.Controls.Add(oButton)
control.Visible = True
control.BringToFront()
Console.WriteLine(control.Name & " " & oButton.Name)
End If
Next
CODE TO CREATE PANELS
Private Sub CreateNewPanel(ByRef pnlName As String, ByRef pnltopx As Integer, ByRef pnlLefty As Integer, ByRef pnlSizex As Integer, ByRef pnlSizey As Integer)
Dim iPanel As Panel
iPanel = New Panel
iPanel.Name = pnlName
iPanel.Enabled = True
iPanel.Visible = False
iPanel.Top = pnltopx
iPanel.Left = pnlLefty
iPanel.Size = New Size(pnlSizex, pnlSizey)
iPanel.AutoScroll = True
Me.Controls.Add(iPanel)
If iPanel.Name = "pnlDepartments" Or iPanel.Name = "pnlDeptItems26" Then
iPanel.Visible = True
iPanel.BringToFront()
End If
End Sub
I then tried doing this and this does not work either:
For Each control In Me.Controls.OfType(Of Panel)
If control.Name = btnPanelName Then
control.Controls.Add(oButton)
End If
If control.Name = "pnlDeptItems26" Then
control.Visible = True
End If
Next
Code that is called to create the panels
CreateNewPanel("pnlDeptItems" & dataDeptId, 608, 5, 429, 479)
dataDeptId is pulled from a database in a loop.
Can someone explain to me why this is not working or what the work around is? I know it has something to do with all the panels that are created being created in the exact same position.
Thanks,
Shawn Mulligan
I found the solution. After reading my post I took notice that for some reason that my paneltopx and my panellefty were reversed and too large for some reason as well as my panelsizey and panelsizex.
I made the adjustments and made sure that all panels visibility was set to false, and now when I set visibility to true, the correct panel displays with the buttons that I created.
Thanks,
Shawn Mulligan
I am attempting to write a simple plugin for MusicBee (a music player app)
I am building on the example provided with the API.
Some background: this plugin is launched when the main .exe (musicbee) launches.
The Configure() function is run when the user goes to the plugin config screen in the options menu.
The
Dim configPanel As Panel = DirectCast(Panel.FromHandle(panelHandle), Panel)
Dim btn1 As New Button
and configPanel.Controls.AddRange(New Control() {btn1})
lines add a button to this config screen which I am using to enable/disable the only function of my plugin.
To provide user feedback I need to change the text of this button (i.e. "ON", "OFF")
The problem: If I declare the button inside the Configure() function I cannot access it from the other click event function. (btn1_Click())
If I declare it globally then when the user closes the config screen (not the whole plugin) btn1 gets disposed (actually configPanel gets disposed by the musicbee API I think). When the user tries to open the config screen again I get an exception because it tries to access btn1 when it was already disposed and is not re-declared.
MusicBee v3.0.6132.15853 (Win6.1), 7 Mar 2017 20:53:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Button'.
There must be a way to declare/setup btn1 so that this works but I don't know how.
Thanks, Timothy.
Imports System.Runtime.InteropServices
Imports System.Drawing
Imports System.Windows.Forms
Public Class Plugin
Private mbApiInterface As New MusicBeeApiInterface
Private about As New PluginInfo
Dim playMode As Boolean
Public Function Initialise(ByVal apiInterfacePtr As IntPtr) As PluginInfo
CopyMemory(mbApiInterface, apiInterfacePtr, 4)
If mbApiInterface.MusicBeeVersion = MusicBeeVersion.v2_0 Then
' MusicBee version 2.0 - Api methods > revision 25 are not available
CopyMemory(mbApiInterface, apiInterfacePtr, 456)
ElseIf mbApiInterface.MusicBeeVersion = MusicBeeVersion.v2_1 Then
CopyMemory(mbApiInterface, apiInterfacePtr, 516)
ElseIf mbApiInterface.MusicBeeVersion = MusicBeeVersion.v2_2 Then
CopyMemory(mbApiInterface, apiInterfacePtr, 584)
ElseIf mbApiInterface.MusicBeeVersion = MusicBeeVersion.v2_3 Then
CopyMemory(mbApiInterface, apiInterfacePtr, 596)
ElseIf mbApiInterface.MusicBeeVersion = MusicBeeVersion.v2_4 Then
CopyMemory(mbApiInterface, apiInterfacePtr, 604)
ElseIf mbApiInterface.MusicBeeVersion = MusicBeeVersion.v2_5 Then
CopyMemory(mbApiInterface, apiInterfacePtr, 648)
Else
CopyMemory(mbApiInterface, apiInterfacePtr, Marshal.SizeOf(mbApiInterface))
End If
about.PluginInfoVersion = PluginInfoVersion
about.Name = "Single Play Mode"
about.Description = "Adds a single play mode i.e play one track and stop."
about.Author = "Timothy Hobbs"
about.TargetApplication = "" ' current only applies to artwork, lyrics or instant messenger name that appears in the provider drop down selector or target Instant Messenger
about.Type = PluginType.General
about.VersionMajor = 1 ' your plugin version
about.VersionMinor = 0
about.Revision = 1
about.MinInterfaceVersion = MinInterfaceVersion
about.MinApiRevision = MinApiRevision
about.ReceiveNotifications = ReceiveNotificationFlags.PlayerEvents
about.ConfigurationPanelHeight = 40 ' height in pixels that musicbee should reserve in a panel for config settings. When set, a handle to an empty panel will be passed to the Configure function
Return about
End Function
Public Function Configure(ByVal panelHandle As IntPtr) As Boolean
' save any persistent settings in a sub-folder of this path
Dim dataPath As String = mbApiInterface.Setting_GetPersistentStoragePath()
' panelHandle will only be set if you set about.ConfigurationPanelHeight to a non-zero value
' keep in mind the panel width is scaled according to the font the user has selected
' if about.ConfigurationPanelHeight is set to 0, you can display your own popup window
If panelHandle <> IntPtr.Zero Then
Dim configPanel As Panel = DirectCast(Panel.FromHandle(panelHandle), Panel)
Dim btn1 As New Button
btn1.Location = New Point(0, 0)
btn1.Size = New Size(150, 25)
btn1.Text = "Single Play Mode: OFF"
playMode = False
configPanel.Controls.AddRange(New Control() {btn1})
AddHandler btn1.Click, AddressOf btn1_Click
End If
Return True
End Function
Public Sub btn1_Click(sender As Object, e As EventArgs) 'toggle play mode
If playMode Then 'We are in single play mode so turn it OFF
playMode = False
btn1.Text = "Single Play Mode: OFF" '*******ERROR HERE*******
If mbApiInterface.Player_GetStopAfterCurrentEnabled() Then
mbApiInterface.Player_StopAfterCurrent() 'disable it
End If
'also disable stopaftercurrent once more for the current song.
Else 'We are in normal play mode so turn it ON
playMode = True
btn1.Text = "Single Play Mode: ON" '*******AND HERE*******
'enable it once
If Not mbApiInterface.Player_GetStopAfterCurrentEnabled() Then
mbApiInterface.Player_StopAfterCurrent() 'enable it
End If
End If
End Sub
' called by MusicBee when the user clicks Apply or Save in the MusicBee Preferences screen.
' its up to you to figure out whether anything has changed and needs updating
Public Sub SaveSettings()
' save any persistent settings in a sub-folder of this path
Dim dataPath As String = mbApiInterface.Setting_GetPersistentStoragePath()
End Sub
' MusicBee is closing the plugin (plugin is being disabled by user or MusicBee is shutting down)
Public Sub Close(ByVal reason As PluginCloseReason)
End Sub
' uninstall this plugin - clean up any persisted files
Public Sub Uninstall()
End Sub
' receive event notifications from MusicBee
' you need to set about.ReceiveNotificationFlags = PlayerEvents to receive all notifications, and not just the startup event
Public Sub ReceiveNotification(ByVal sourceFileUrl As String, ByVal type As NotificationType)
' perform some action depending on the notification type
Select Case type
Case NotificationType.PluginStartup
' perform startup initialisation
Select Case mbApiInterface.Player_GetPlayState()
Case PlayState.Playing, PlayState.Paused
' ...
End Select
Case NotificationType.TrackChanged
If playMode Then 'if single play mode is enabled
If Not mbApiInterface.Player_GetStopAfterCurrentEnabled() Then
mbApiInterface.Player_StopAfterCurrent() 'enable it
End If
End If
End Select
End Sub
' return an array of lyric or artwork provider names this plugin supports
' the providers will be iterated through one by one and passed to the RetrieveLyrics/ RetrieveArtwork function in order set by the user in the MusicBee Tags(2) preferences screen until a match is found
Public Function GetProviders() As String()
Return New String() {}
End Function
' return lyrics for the requested artist/title from the requested provider
' only required if PluginType = LyricsRetrieval
' return Nothing if no lyrics are found
Public Function RetrieveLyrics(ByVal sourceFileUrl As String, ByVal artist As String, ByVal trackTitle As String, ByVal album As String, ByVal synchronisedPreferred As Boolean, ByVal provider As String) As String
Return Nothing
End Function
' return Base64 string representation of the artwork binary data from the requested provider
' only required if PluginType = ArtworkRetrieval
' return Nothing if no artwork is found
Public Function RetrieveArtwork(ByVal sourceFileUrl As String, ByVal albumArtist As String, ByVal album As String, ByVal provider As String) As String
'Return Convert.ToBase64String(artworkBinaryData)
Return Nothing
End Function
End Class
I am trying to create a document writer in vb.net
So I decided to add a tab control, so I can create a new tab when I press a button. I would like to save the text in the tab that is open. I created a function the returns the text depending on what tab is open, but that only works for the two default tabs. I don't know how I would save if I've created a new tab.
The function to get the text is this:
Public Function getText() As String
If tabPage1.Visible = True Then
Return mainText.Text
ElseIf tabPage2.Visible = True Then
Return textBox1.Text
End If
End Function
I've done some research online, I've even looked at SharpDevelop's source code and I couldn't find anything.
Thanks in advance!
EDIT :
Public Sub setText(Byval value As String)
If tabPage1.Visible = True Then
mainText.Text = value
ElseIf tabPage2.Visible = True Then
textBox1.Text = value
End If
End Sub
Does anyone know how I would do an open feature determined on what tab is open (as before.)
If I understand you correctly, you are trying to have a textbox in each of your tabPages generated dynamically. If this is the case you could generalize your GetText function with this code
Function GetText() As String
If tabControl1.SelectedTab IsNot Nothing Then
Return tabControl1.SelectedTab.Controls.OfType(Of TextBox)().First().Text
End If
End Function
This requires that you have at least one textbox in each page (and your TabControl is named tabControl1). The SelectedTab property (if not nothing) is the current tabPage displayed by your tabControl
I am looking for a way to design things differently in my project. Instead of using TabControls I wish to use Buttons (Instead of pressing the tabs on the top I would like to press the Buttons on the left-side). These buttons when pressed they have their own Panel where each has their own respective content.
Select Case tabAdmin.SelectedIndex
Case 0
If txtCode_Patient.Text = "" Then
txtCode_Patient.Focus()
Else
cmdAdminister.Focus()
End If
Case 1
If txtD_Patient.Text = "" Then
txtD_Patient.Focus()
Else
cmdRefresh.Focus()
End If
Case 2
If txtI_Patient.Text = "" Then
txtI_Patient.Focus()
Else
cmdI_CUser.Focus()
End If
Case 3
If txtStat_CS.Text = "" Then
txtStat_CS.Focus()
Else
cmdStat_Refresh.Focus()
End If
End Select
The code above is similar to what my project acts and it works with TabControls. I want to do a similar thing but this time, like I said before, pressing Buttons on the left-side. How can I do a similar thing ?
UPDATE:
I found a way for this one but now my concern is how do I make it look like one of its default button 3D look-alike?
Public Class Tab
Inherits TabControl
Private Property DoubledBuffered As Boolean
Sub New()
SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.ResizeRedraw Or ControlStyles.UserPaint, True)
DoubledBuffered = True
SizeMode = TabSizeMode.Fixed
ItemSize = New Size(30, 110)
End Sub
Protected Overrides Sub CreateHandle()
MyBase.CreateHandle()
Alignment = TabAlignment.Left
End Sub
Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)
Dim B As New Bitmap(Width, Height)
Dim G As Graphics = Graphics.FromImage(B)
G.Clear(Color.AliceBlue)
For i = 0 To TabCount - 1
Dim TabRectangle As Rectangle = GetTabRect(i)
If i = SelectedIndex Then
'//Selected
G.FillRectangle(Brushes.DarkSlateGray, TabRectangle)
Else
'//Not Selected
G.FillRectangle(Brushes.AntiqueWhite, TabRectangle)
End If
G.DrawString(TabPages(i).Text, Font, Brushes.Black, TabRectangle, New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
Next
e.Graphics.DrawImage(B.Clone, 0, 0)
G.Dispose() : B.Dispose()
MyBase.OnPaint(e)
End Sub
End Class
Use the CheckBox control instead of Button, but set Appearance = Button, that way it looks exactly like a button can remains in the "pressed" state when clicked.
To shift between content, put each of your sub-forms into their own UserControl instances, then host them within a Panel control, then switch the .Visibility property of each sub-form according to which CheckBox was clicked.
There is an Outlook-style side bar available on Code Project. It has a VB version as well as C# and although it's knocking on a bit now, you could always adapt this to look a bit nicer. I have used it in the past and it worked pretty well as I recall.
You can set the selected tab via tabAdmin.SelectedIndex = 0 (or 1, 2, etc, but remember it is 0 based)
You may also set the tab by the tab's name via tabAdmin.SelectedTab = TabName
Use a common click event handler for the buttons. Store the relevant tabindex in the Tag property of the buttons. Then tabAdmin.SelectedIndex equals the tag of the clicked button cast as integer.
In my access database before I was using a list box in the form for having list of items and I had below code for opening new form after right click on each selected item in list box.
Private Sub ItemList_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Const RIGHTBUTTON = 2
If Button = RIGHTBUTTON Then
DoCmd.OpenForm "frmShortcut_GenerateTask"
DoCmd.MoveSize udtPos.X * mp.TwipsPerPixelX, udtPos.Y * mp.TwipsPerPixelY
End If
End Sub
Now I am using a continuous form instead of list box and I have defined a [isselected) field for selecting each record in continuous form after clicking on that. Now my problem is how I have to write code for right clicking and opening new form.
I used the same code I had used for list box, but it does not work and nothing happened.
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Const RIGHTBUTTON = 2
If Button = RIGHTBUTTON Then
DoCmd.OpenForm "frmShortcut_GenerateTask"
DoCmd.MoveSize udtPos.X * mp.TwipsPerPixelX, udtPos.Y * mp.TwipsPerPixelY
End If
End Sub
Private Sub P_Click()
On Error Resume Next
Me.IsSelected = Not Me.IsSelected
' Save the status
Me.Dirty = False
' Force conditional highlighting
P_ForceHighLight
' Update display in SF_Selected
Me.Parent("SF_Selected").Requery
ActiveControl.SelLength = 0
On Error GoTo 0
End Sub
I recommend either using a DoubleClick event in all of your textboxes and combos, or else putting a small button at one edge of your continuous form that allows the user to open records. Right-click is going to give you problems (so will labels and image controls) because this event doesn't cause (or ensure) that the Form's internal Recordset Bookmark property is actually moved to the record they right-clicked on. In my experience, only buttons, textboxes, and comboboxes will move the Bookmark to the record the user is trying to select.
To Test this, try putting code at the top of your different routines that shows you what record is selected:
MsgBox "RecordID = " & Me!RecordIDField
If you are consistently getting the correct ID, then your problem has to do with how your opening your new form, passing parameters or arguments, etc.