473,324 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

setting form properties during runtime

OK--Beginner question--

I have a project with one form -- Form1. To change the text, why can't
I use "Form1.Text = something"? Instead I have to use
"Form1.ActiveForm.Text = Something". As an exercise, I rewrote a timer
app that I wrote in VB 5.0. You set the time, and when it runs, it
minimizes until the time is up, and then pops back up again and gives an
alerting sound. In VB 5.0, I was able to write the time to the forms
text property, while the timer was counting down and the form was
minimized, so you could see how much time was left by looking in the
task bar. Now, when I try to do this and the form minimizes, it throws
an exception when the time (ie form text) changes -- (I guess when the
form is minimized, it is no longer an active form). I'm confused.

Jim
Jan 15 '07 #1
2 4076
Jim Madsen <ju****@nobody.comwrote in news:uM7uWFOOHHA.448
@TK2MSFTNGP04.phx.gbl:
I have a project with one form -- Form1. To change the text, why can't
I use "Form1.Text = something"?
Is form1 your instance name or your class name?

If it's your class name, you must refer to the current instance.

For example, if you displayed the new form as:

Dim _MyForm as new Form1

You can change the title by going _MyForm.Title = "SomeTitle"
Jan 16 '07 #2
Jim Madsen wrote:
I have a project with one form -- Form1. To change the text, why can't
I use "Form1.Text = something"? Instead I have to use
"Form1.ActiveForm.Text = Something".
Forms are Classes - always have been - so to set the property on any one
of them, you must have a reference to the object you want to manipulate.

VB no longer maintains a "default" reference (e.g. "form1") to each
Form. When you create the Form object, you have to hold that reference
and use it to access the Form object, as in

Sub New()
Dim f1 As New Form1
f1.Text = "Set the Form's Title"
...
End Sub

ActiveForm is a Shared method on the Form class that returns the
currently active Form anywhere in your application. Because your Form1
Inherits from Form, you get all the Shared method for free, so

Form1.ActiveForm

is the same as

System.Windows.Forms.Form.ActiveForm
In VB 5.0, I was able to write the time to the forms text property,
while the timer was counting down and the form was minimized,
so you could see how much time was left by looking in the task bar.
Now, when I try to do this and the form minimizes, it throws
an exception when the time (ie form text) changes -- (I guess when the
form is minimized, it is no longer an active form).
That's correct. There's no longer an ActiveForm in your application so
ActiveForm returns Nothing and Boom!

Your timer is part of your Form1 class, and you can alsways access the
Form (or, rather Class) it's within via the keyword "Me".

Private Sub tmrTick( ... ) _
Handles tmrTick.Elaped '?

Me.Text = DateTime.Now.ToString( "HH:mm:ss" )

End Sub

HTH,
Phill W.
Jan 16 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Nathan Baulch | last post by:
I have an XML file that my application reads at runtime: <form> <control clsid="B5ECA9DC-879F-40BC-9298-3E399E099C0B"> <name>btnGO</name> <top>10</top> <left>10</left> <myint>273</myint>...
2
by: manohar.shankar | last post by:
Hi, I have been searching on this topic for quite sometime and didnt get any answer. Is there a way I can extend/add methods/properties to a C# class during runtime. eg., I have class:...
8
by: Grant | last post by:
Hello, Ive got a form with 3 textboxes - one under the other. When I set the anchor to top, left, right, and bottom for each of them and resize the form at runtime, they change size in relation...
1
by: Frank Yamrick | last post by:
I am trying to program an application that requires a large number of screnes that are very similar in the respect that all the bottons and labels interact with each other with the same...
2
by: Patrick | last post by:
I remeber seeing a sample on th e.net (and in fact i tried this too - but lost the source code), to achieve the following. Dropping a control onto a form, which is exactly like the properties...
5
by: Alex Glass | last post by:
I have created a winforms application and I designed it with the normal display settings, (96DPI) however, when I set the font settings to 120 DPI, my application text labels look all messed up. ...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
7
by: Ronald S. Cook | last post by:
In a .NET Windows app, if I set somehting like the title of the form to "MyApp" at run-time, will that make the app run slightly slower than if I had set the title at design-time? Thanks, Ron
8
by: Andrus | last post by:
..NET 2 Winforms application. How to create new setting and set it default value in userSettings section of app.config file or overwrite existing setting value ? I found code below in this list...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.