473,651 Members | 2,790 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Create Label Via User Control Property Page

devonknows
137 New Member
Hi, I have a property page for my user control that has a text box and a button on it, when the user enters text into the text box and clicks the button i want a new label to appear on the user control but im unsure of how to do this, And i dont want to have to add loads of blank labels as that is rather impractical and would take up unecessary memory.

If anyone could help i would be most appreciated
Kind Regards
Devon
Feb 2 '08 #1
8 6393
daniel aristidou
491 Contributor
Hi, I have a property page for my user control that has a text box and a button on it, when the user enters text into the text box and clicks the button i want a new label to appear on the user control but im unsure of how to do this, And i dont want to have to add loads of blank labels as that is rather impractical and would take up unecessary memory.

If anyone could help i would be most appreciated
Kind Regards
Devon
Not sure if this will work...ive never tried creating a control
From code...this might might be incorect...if it doesnt work...most likely the "New lbl" line needs to be changed slightly

Expand|Select|Wrap|Line Numbers
  1. If Textbox.text = "" =false then
  2. New lbl as label
  3. lbl.position.x = 'Your positioning value
  4. lbl.position.y = 'your positioning value
  5. lbl.text = textbox.text
  6. End if
Feb 2 '08 #2
devonknows
137 New Member
Not sure if this will work...ive never tried creating a control
From code...this might might be incorect...if it doesnt work...most likely the "New lbl" line needs to be changed slightly

Expand|Select|Wrap|Line Numbers
  1. If Textbox.text = "" =false then
  2. New lbl as label
  3. lbl.position.x = 'Your positioning value
  4. lbl.position.y = 'your positioning value
  5. lbl.text = textbox.text
  6. End if
Apologies i should mentions that this is for VB6, VB6 doesnt have the .position methods, i have tried
Expand|Select|Wrap|Line Numbers
  1.         Dim lbl As Label
  2.         lbl.Top = 100
  3.         lbl.Left = 100
  4.         lbl.Caption = TextBox.Text
  5.         lbl.Visible = True
  6.  
but all i get is an error saying
"Object Variable or With Block Variable Not Set"

Hope this helps you to help me
Kind Regards
Devon
Feb 2 '08 #3
daniel aristidou
491 Contributor
Could you tell be where exactly...the debugger stops on the code...
also change dim lbl as labale to dim xlbl as new label
lbl by itself might cause error.....try xlbl
Feb 2 '08 #4
devonknows
137 New Member
Could you tell be where exactly...the debugger stops on the code...
also change dim lbl as labale to dim xlbl as new label
lbl by itself might cause error.....try xlbl
Ok, The subroutine im using on the UserControl is this

Expand|Select|Wrap|Line Numbers
  1. Public Sub AddItem(strTemp As String)
  2.     Dim lbl As New Label
  3.     lbl.Top = 100
  4.     lbl.Left = 100
  5.     lbl.Caption = strTemp
  6.     lbl.Visible = True
  7. End Sub
  8.  
And on the Property page that is assigned to to the user control im using this
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2.     frmMain.WindowsTaskBox1.AddItem "TESTING"
  3. End Sub
  4.  
But im getting the error message when Command1_Click( ) is called.
"An Instance of frmMain cannot be created as its designer window is still open"

Apologies in advance, this is my first user control so still getting used to alot of the commands and such

And when i put WindowsTaskBox1 .Additem "TESTING" in the frmMain_Load() Method i get.
"Invalid Use of New Keyword" referring to "Dim lbl As New Label"

Kind Regards
Devon
Feb 2 '08 #5
devonknows
137 New Member
Can no-one help me in this matter? Adding a label to a usercontrol during design time via the UserControl property page? if anyone can help id be most appreciated.

Example. When you highlight your user control that has been placed on your form, and click "Custom.." in your properties window, you get the properties window that you have assigned (Custom or VB built in) I have a text box and a command button, so when the user clicks the command button it automatically adds a label to the user control whilst still in design mode.

Kind Regards
Devon
Feb 7 '08 #6
Kai001
1 New Member
Devonknows:

Here's some simple code for VB6 to create and place a new label.

Expand|Select|Wrap|Line Numbers
  1. ' General declarations:
  2. ' Create a new control to use as a label
  3. Private MyNewLabel As Control
  4. ' Create a variable that we will use to make sure no two labels have the same name
  5. Dim LabelCount as Integer
  6.  
  7. ' A buttons' click event:
  8. Private Sub Command1_Click()
  9.  
  10. ' The following function is adding a new label to the form this code is on. The functions' parameters are as follows: Add( The type of control, The control's new name). We add the LabelCount variable to the end of it in order to make sure we have no controls with duplicate names.
  11. Set MyNewLabel = Me.Controls.Add("vb.label", "MyNewLabel" & LabelCount)
  12.  
  13. ' You MUST set visible to true if you want the new control to be visible
  14. MyNewLabel.Visible = True
  15. ' Set how far the label is from the left
  16. MyNewLabel.Left = 100
  17. ' Set how far the label is from the top
  18. MyNewLabel.Right = 100
  19. ' Finally, set the caption of the label
  20. MyNewLabel.Caption = "This is a new label!"
  21.  
  22. ' Increment the LabelCount variable up by one
  23. LabelCount = LabelCount + 1
  24.  
  25. ' End our sub
  26. End Sub
  27.  
I hope this helps, I registered just to post this, as I only learned how to do this a month ago.

See ya,
Kai
Feb 15 '08 #7
daniel aristidou
491 Contributor
Thanks kai
Knew we where missing something
Feb 16 '08 #8
devonknows
137 New Member
Thanks kai
Knew we where missing something
When i add this to the property page for the user control, and then access the property page when i click Custom on the properties for my user control i get

'Method or Data Member not Found' and it highlights 'Me.Controls.Ad d.

im not sure if i mentioned earlier that i want the control to add during design time, for example the toolbar control, when you click add button, the toolbar control on the form automatically adds a button when you click ok/apply

ive looked at the code behind the toolbars and stuff and ive found that it creates like a class for a button, i was jus wondering if i need to do the same with a label, and if i created a label class, what information would i need in it. and how would i get it to add an instance of it to the user control on my form.Unfortunet ly ive looked everywere i can think of to find information on this but cant seem to find any information. So anyone that has created a custom toolbar control, or a status bar control or anything along them lines, any helped would be appreciated

Kind Regards
Devon
Mar 14 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

7
3520
by: Bil Muh | last post by:
Esteemede Developers, I would like to Thank All of You in advance for your sincere guidances. I am developing a software using Visual C++ .NET Standard Edition with Windows Form (.NET) template. Briefly -------------------------------------------------------------------------------------------- I need to create dynamically some controls on the forms, and display these
3
1336
by: DC Gringo | last post by:
I'm trying to use a label control to show the # of records in my datagrid and think I'm stuck on something simple...please help: Error is: Name 'myDataSet1' is not declared. FYI, it works fine if I use an integer value like "100" rather than myDataSet1.Tables("CommunitiesT1") -----MY LABEL CONTROL------
7
8956
by: Ed West | last post by:
Hello, I have a simple form with some input boxes. After validation if one fails, then I would like to at the top of the page say something like "The following fields in red are required" and then change the label in front of the textbox or dropdown list to red... is this possible with asp.net? It seems you can only put a RequiredFieldValidator on the page, and if it fails validation then that text is displayed... ? Thanks
2
2203
by: Quentin Huo | last post by:
Hi: I have a user control and I want to dynamically create a Label control and TextBox control when the button "add more author name" is clicked. I did like this: 1. there is a "PlaceHolder" control "ph" in the user control; 2. create a Label control and TextBox control when in the "add" button
3
1787
by: Patrick.O.Ige | last post by:
I created a USERCONTROL and i want to call a LABEL from an ASPX page. The USERCONTROL is in the ASPX page I have the label :- Label lblstr = new Label(); And displaying using:- lblstrp.Text=lblstr.Text; <asp:label id="lblstrp" BorderColor="#ff3333" BorderStyle="Dashed" BorderWidth="3" ForeColor="#0033cc" Font-Size="25" Runat="server" Width="55%" BackColor="#ffff00"></asp:label>
1
9208
by: nospamjac | last post by:
Hi, Is there a way to update the text of an asp:label on a webform without refreshing the entire page? What is called by button clicks and other events that refresh a webform control? See the example WebForm1.aspx and WebForm1.aspx.cs code below: WebForm1.aspx =======================================================
0
1283
by: lupina | last post by:
Hi I'm making web user control in ASP .NET 2.0 (TextBox + Button). It works allright, but I need to add property and event to it, that would be visible in VS Designer. With property I havn't any troubles: using System.ComponentModel; private string message;
16
3872
by: Mich | last post by:
Hi, i'm building an web application for anonymous users. They can take a look in the website, nothing more. In order to perform other actions, the anonymous user must be logged. So i create an aspx page with the CreateUserWizard control. The user can fill his username, password etc .... My problem is: when an user fills everything and clicks on button "create an account", nothing happens (no error, but no user account created). I...
1
2644
by: Jim in Arizona | last post by:
On one page I have a datalist where a message is bound to a label. On another page I have the datalist which allows for the insert of new message as well as being able to edit those messages. The editing (EditItemTemplate) has a textbox that loads the message into its text property. The problem I'm running into is working with vbCrLf and <brinterchangeably between the textbox on the admin page and the label on the general message page. I...
0
8357
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8277
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8465
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8581
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7298
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5612
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4285
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1910
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1588
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.