-
Sep 3rd, 2023, 07:49 AM
#1
Thread Starter
Frenzied Member
Interacting with custom made controls
I have a custom control that has a tab control that when a new tab is created it also has a toolstrip with a few buttons and a text box. I want to interact with those as they exist e.g selected index - and as needed from the form (Very important) - one of the libraries I am using doesn't work well with button interactions outside of the parent form. And I cannot have the control placed on the tabs as part of the custom hardcode either as it does not work correctly (and known issue they basically said it was unsupported lmao)
I have also slimmed the control to be WITHOUT the tab control and just try and add this on the fly, but that too is failing.
My brain is weak from not really doing VB.NET for a while so looking for inputs on solutions.
I have tried a simple address e.g.
Code:
Private Sub ButtonFavorites_Click(sender As Object, e As EventArgs) Handles BrowserURLBar1.ButtonFavorites.Click
' Handle the Favorites button click event
MessageBox.Show("Favorites button clicked!")
End Sub
Can someone jar my brain and explain how to interact with buttons on a custom control? It is probably easier than I am making it.
Disclaimer: When code is given for example - it is merely a example. •
•
•
Unless said otherwise indicated - All Code snippets advice or otherwise that I post on this site, are expressly licensed under Creative Commons Attribution 4.0 International Please respect my copyrights.
-
Sep 3rd, 2023, 10:07 AM
#2
Re: Interacting with custom made controls
You don't interact with child controls. If you have created what sounds like a user control, all interact from the outside should be done with that. Any members of child controls that you need to work with from the outside should be exposed by what I call pass-through members. For instance, if you had a child TextBox then you might add a property to the parent control that exposed the Text property:
vb.net Code:
Public Property TextBox1Text As String
Get
Return TextBox1.Text
End Get
Set
TextBox1.Text = value
End Set
End Property
In the case of a Button, it is the Click event that you want to pass through:
vb.net Code:
Public Event Button1Click As EventHandler
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
RaiseEvent Button1Click(Me, EventArgs.Empty)
End Sub
-
Sep 14th, 2023, 04:21 PM
#3
Thread Starter
Frenzied Member
Re: Interacting with custom made controls
Thanks that seems to send me in the right direction. I have started to also add a new tab button, by painting the button on the control, it seems that it works in the designer but not at run time. May start a new thread for that issue as it seems to be a whole new slew of what ifs on a solution.
Disclaimer: When code is given for example - it is merely a example. •
•
•
Unless said otherwise indicated - All Code snippets advice or otherwise that I post on this site, are expressly licensed under Creative Commons Attribution 4.0 International Please respect my copyrights.
-
Sep 14th, 2023, 06:07 PM
#4
Re: Interacting with custom made controls
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 18th, 2023, 08:48 AM
#5
New Member
Re: Interacting with custom made controls
Interacting with custom-made controls in Visual Basic (VB) involves creating, manipulating, and responding to events of controls that you design or customize for your VB application. Here's a general overview of how to work with custom controls in VB:
Create a Custom Control:
You can create custom controls by either inheriting from existing controls (user controls) or building entirely new controls from scratch.
Design the Custom Control:
Use the Visual Studio Designer to design the appearance and behavior of your custom control.
Customize properties, events, and methods as needed to achieve the desired functionality.
Add Custom Control to a Form:
In the VB.NET designer, you can drag and drop your custom control onto a Windows Form or a user control.
Interact with the Custom Control:
Set properties: You can set properties of your custom control programmatically to configure its appearance and behavior.
Handle events: Register event handlers for the custom control's events. This allows you to respond to user actions or changes in the control's state.
Call methods: Invoke methods of the custom control to trigger specific actions or behaviors.
-
Sep 19th, 2023, 03:50 AM
#6
Addicted Member
Re: Interacting with custom made controls
You can also create Public methods or functions and pass arguments in. Here are some examples, obviously the controls in this example are just created for example and dont belong to any container so this wont work unless the controls are visible on a form/usercontrol. Just to give you an idea.
Code:
Public Class Class1
Private _Class2 As New Class2
Private Button1 As New Button
Public Sub New()
AddHandler Button1.Click, Sub()
Dim SomeObj As New Object 'can be anything
_Class2.SetButton1Stuff("Your Button Text", SomeObj)
_Class2.ClickButton1("Your msg txt")
End Sub
End Sub
End Class
Public Class Class2
Private Button1 As New Button
Private Msg As String = String.Empty
Public Sub New()
AddHandler Button1.Click, Sub()
MsgBox(Msg)
End Sub
End Sub
Public Sub ClickButton1(ByVal MsgTxt As String)
Msg = MsgTxt
Button1.PerformClick()
End Sub
Public Sub SetButton1Stuff(Optional ButtonText As String = "Default Text", Optional _Tag As Object = Nothing)
Button1.Text = ButtonText
Button1.Tag = _Tag
End Sub
End Class
-
Sep 19th, 2023, 03:53 AM
#7
Addicted Member
Re: Interacting with custom made controls
 Originally Posted by SKPTitleLLC
Interacting with custom-made controls in Visual Basic (VB) involves creating, manipulating, and responding to events of controls that you design or customize for your VB application. Here's a general overview of how to work with custom controls in VB:
Create a Custom Control:
You can create custom controls by either inheriting from existing controls (user controls) or building entirely new controls from scratch.
Design the Custom Control:
Use the Visual Studio Designer to design the appearance and behavior of your custom control.
Customize properties, events, and methods as needed to achieve the desired functionality.
Add Custom Control to a Form:
In the VB.NET designer, you can drag and drop your custom control onto a Windows Form or a user control.
Interact with the Custom Control:
Set properties: You can set properties of your custom control programmatically to configure its appearance and behavior.
Handle events: Register event handlers for the custom control's events. This allows you to respond to user actions or changes in the control's state.
Call methods: Invoke methods of the custom control to trigger specific actions or behaviors.
Would be nice to downvote this gpt response
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|