Accessing a form's tooltip from another class in visual studio (vb.net) - vb.net

I am quite new to visual studio. Developed previously with vba.
Encountering a problem writing a language translation class.
The language dependent values are stored in a localdb table every row having formname , controlname and controlproperty as wel as a column per language.
The Language class Handles the translations at runtime. For forms I use a Sub FormUpdate(frm as Form) called from the form's load event as FormUpdate(Me) it checks the form's language kept in a custom parameter against the current language and updates the .text property of the controls on the form that are exposing some language specific text (Buttons, Labels, Tabcontrol etc..).
However I could not solve how to access and update the form's Tooltip component from the language class. (in vba it was easy as every control was exposing it's Controltiptext property)
In the form's class you would use MyTooltip.Settooltip(CtrlName,Text) but I could not figure out how to do that from another class (the tooltip component is not part of the form's controls - and I could not figure out nor find info how to do it) ??
Could someone advise pls?

I was so focused on finding a similar way to the one I used before that I did not see the easy way to resolve it - not yet enough accustomed to the new environment.
Sure, I am interested in an answer to my question but instead of making it too complicated using external components I'll do it the easy way by overloading the FormUpdate sub adding a sub with an extra parameter as Tooltip.

Related

undo for non textbox controls

new to .net coming from vba decided to rewrite a management app using vb.net and SQL Server.
Started writing the base library for my application.
I created custom controls to use in my application that would expose a Zoom function, background color for the current active control a .modified property similar to the one available in textbox and some extra other properties (SQLTableName, SQLColumnName, ...) to enable iterating through a container (form) for modified controls and Update/Insert into a SQL table via a SQLProcessClass.
Concurrently I'd like to also implement a simple undo functionality.
My first idea was to add a PrevValue variable set in the OnEnter event if the Modified property is False, exposing an OldValue property and an Undo method in the custom controls.
However I found that the TextBoxBaseClass already exposes an Undo method and that there is an UndoEngineClass available.
Unfortunately the vs helpfile does not give examples of how to use / implement that class.
Could someone explain the usage of the UndoEngine class non-textbox controls and if it is advisable to use it or rather write my own (as I first intended to do - I also found some interesting articles about undo/redo classes) but why reinvent the wheel in case .net already provides a class for it.
thks

VBA OOP extending existing classes

I'm a rookie at VBA(Excel) but I know some OOP stuff from java. What I want to do is extend the class MSForms.TextBox to add my own constructors and properties. I've tried using the implements keyword but my class won't compile. It would also be helpful to add these fields into some kind of container variable since they're arranged in a 9x9 pattern. Here's what I want my custom textbox to do. (It's for a game)
I need to be initiate it and place it on the form and put initial text into the box based on what is passed to the constructor. I also would like to have it check the values at runtime with an event to make sure they comply with the game rules. If it does not comply I would like to change the background color to red.
I'm able to do all of this when I just make a bunch of form controls the old fashioned way and use a sub controlled by a button to check the text box values.
Any help on extending classes would be much appreciated.
Thanks
I don't think you can do that in VBA. I would keep two arrays, one array of TextBox and one array of a new class representing your extended properties. Then you keep them in sync. e.g. Textbox #71 and extended properties #71.
You can look at the following link for making and working with control arrays.
http://www.siddharthrout.com/index.php/2018/01/15/vba-control-arrays/

Issue with OpenFileDialog and threading

I just upgraded from VS 2005 to VS 2012. This is a new issue that I do not understand. I am using the default "Form1" class the VS automatically creates. I added a button to open a file open dialog and when I click the button I get this error:
Current thread must be set to single thread apartment (STA) mode before OLE calls can be >made. Ensure that your Main function has STAThreadAttribute marked on it. This exception >is only raised if a debugger is attached to the process.
I have added " to Public Class Form1:
<STAThread()> Public Class Form1
But I get this...
Attribute 'STAThreadAttribute' cannot be applied to 'Form1' because the attribute is not >valid on this declaration type.
I have searched but get some info telling me that I need to set the entry point (Form1 I believe) to be Single Thread Attribute but the above code does not work.
How?
The <STAThread()> attribute cannot be added to classes like your form. It only works when it is applied to the Main function, which is the entry point of your application.
But VB.NET hides this function from you because it is rare that one needs to mess with Main in a WinForms application. It is just needed to get the plumbing set up for your app, which the compiler can manage for you. This is controlled by the "Application Framework" checkbox in the project options. If this is checked, the compiler automatically generates the Main function and the required plumbing. You can disable this option, but it makes life quite a bit harder for the average WinForms developer because you'll have to write and maintain your own Main function.
The real question here is why this is a problem at all. The compiler-generated Main function for a WinForms application is always going to have the STAThread attribute applied to it. That is just how the WinForms framework is designed to run. If that is not happening, then there is something badly wrong with your project. I would recommend scrapping it and starting over letting Visual Studio create a new WinForms project from one of the built-in templates. Everything should Just Work™.
The other option, of course, is that you're trying to display the OpenFileDialog on a separate thread (other than your main UI thread). But from your description in the question (adding a button to the form to display the dialog), it doesn't sound like this is the case. Regardless, the solution is not to do that. For example, if you're using a BackgroundWorker to do work on a non-UI thread in order to keep the UI responsive, that's great, but you'll want to do all of the UI stuff like showing an OpenFileDialog on the main UI thread before invoking the BackgroundWorker. There is a way to set a particular thread's apartment state using the SetApartmentState function, but I really don't recommend showing an OpenFileDialog on a background thread.

Creating your own component in vb.net 2008

How do you create your own custom component for vb.net 2008? I want it to simply output to a .dll, not a whole winforms app.
So, here is what I have done so far:
Made a class library project
Added a custom control object
Confused myself badly
Googled it, to no avail
How can I control the component? For example, I want my component to not have a visible design view, I want it to stay below like the stopwatch component and the notifyicon component and such, it is not something to be designed. Then, how do I edit the possible properties a user can control, and make them effect the end result? What do I place the code which powers the component on? The class library file, or something else?
Thanks for your help! I have a whole set of components I am going to create, this will get me going much faster than trial and error.
I think you may want to check some walkthrough on how to create components. Such as this one: Walkthrough: Authoring a Component with Visual Basic. Once you are done with that one, there are more walkthroughs on various related topics, such as how to use design-time support, implementing designers and so on.
OK... This is a really abbreviated example. You should start by basing yous off of an existing .net component.
Public Class MyControl
Inherits DataGridView
'...add your properties/functionality...'
End Class
Then compile the DLL, and add it as a reference to whatever project you are working on. Once added, you can add the controls in the DLL into your toolbox.
This has more instructions on how to modify a UserControl (slightly different from the one above, but it explains well. This is a general explanation.
#comments -
Yes, there, are things that will do what you want. Start with a class that inherits Form instead of DataGridView in the example I gave you, and the changes described in the links provided.
"Your properties and functionality" is whatever you want to do that the base control does not do.

Can I change properties of inherited controls at design time?

I am using visual inheritance and was wondering if there is a way to change the properties of inherited controls at design time, preferably in the form designer. If not, then in the designer code.
I have my control declared as Public in the base class. I can access it in the child form code, but not in the form designer. Is this just not possible?
There are limitations placed within visual studio for visual inheritance. Unfortunately, derived forms\usercontrols cannot modify controls containing collections within the base, namely DataGridViewRows, ToolStrips, ListViewColumns, etc.
Microsoft Bug Report
There are ways around this in certain situations. Create a protected property in the base class that exposes the exact properties of the control you wish to modify (DataGridView.BackgroundColor, or ListView.Columns).
Your base form should be able access this property to change the components needed. I've done this for ListView.Columns, and DataGridView.rows successfully, however ToolStrip.Items would not work.
It seems to work only for certain controls, but not all and I can't understand why. On my base form I have a TabControl that within it is a ComboBox, a ToolStrip, and a DataGridView. All of them are set to Public, but I can only modify the properties of the ComboBox and not the other two controls.
I have no idea why this is.
You need to change your control visibility. Put the control property Modifiers on public and recompile the project and then you can change properties of the inherited control.