Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Creating a custom control

Posted on 2006-07-11
14
Medium Priority
?
162 Views
Last Modified: 2010-04-23
I need a little help with this.  I'm trying to create a custom control - based off a label, that will take the current logged on user ID (my.user.name) and convert it to the user's full name.

I have the code to accomplish all of this - but I can't seem to get it to work the way I'd like.

I want, in the end, to have this custom-label, that when placed on a form and compiled, will show the above information without any other coding.

I'm really new to custom controls, so presumably that's where my problem lies to begin with.
Anyone more experienced care to lend a hand?  I'm using both .net 2003/2005 -but I'd rather get it working in the newer version.  Thanx! (I can post code if necessary)
0
Comment
Question by:sirbounty
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
14 Comments
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 17080784
Okay... what isn't working about it? :)
0
 
LVL 67

Author Comment

by:sirbounty
ID: 17080921
When I add it to a form, it only displays the name of the control...(AD UserName1)
0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 17080977
So... you created a new user control, and then added the controls to it. Then you put your code into the user control, *** rebuilt the application ***, then added the control to the form?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 67

Author Comment

by:sirbounty
ID: 17081026
I *think* so?  Again - this was like my legitimate second attempt - and the first was guided by my textbook.

I created a new project / windows control library
I then deleted the default control (textbook said so) and readded user control, naming it appropriately.
Then, when I entered
Inherits System.Windows.Forms.Label
I got an error - and let the 'autocorrect' method fix it (I forget the actual error - but apparently somewhere else, it was still dependent on usercontrol, rather than specific label).

One item of note - when I do this under 2003, it adds the "Windows Form Designer generated code".
It doesn't do this under 2005 (for me anyway).

Perhaps that's the problem and that section contains whatever I'm missing.  Though I'm not sure why it doesn't auto generate nor why it flags my inherits section as an error initially (well, I know 'why' - I just don't know why it works without extra effort in 2003, but not in 2005).

I'm not against restarting this from scratch either if you want to walk me through it.  I want the control based off a label and when the form is loaded, this routine is run to establish the AD username.  I've got the code for it currently in the Public Sub New, under the 'Add any initialization after the InitializeComponent() call, section...
0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 17081042
2005 does autogenerate.... it just puts it in a Partial Class in a hidden file so that you can't mess with it.

More later -- have to head to the office.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 17081202
Ok - no rush.  Kind of playing around with creating my own in a real-world scenario.  I think this might be beneficial for an upcoming project...
0
 
LVL 67

Author Comment

by:sirbounty
ID: 17322469
Not that points really matter to me - but 'technically', I was waiting for Chaosian to respond, based upon his last post:

"More later -- have to head to the office."

I would like to continue this if he's still around.  Otherwise, I can open a new question later.
0
 
LVL 24

Accepted Solution

by:
Jeff Certain earned 2000 total points
ID: 17323272
Okay....

I'll respond :)

When you create a user control in VS2005, it hides all of the code that used to be autogenerated in the main class. It puts it into a partial class that it hides from you. This way, you can't change the stuff you're not supposed to be changing.

Usually, I create my controls as part of a project. However... I'll walk through the process for you here:
1. Create a new Windows Control Library project.
2. Delete the default control.
3. Right-click on the project. Select Add>>User Control. Name it appropriately.
4. There are two things you can do now. The easiest is to simply add a label to your control, then add the properties and code you require. The harder way is to click on "show all files" in the solution explorer, expand your control and open the designer. This is where the partial class is hiding. You can then change the inheritance to inherit label. Another error will show up due to an Autoscale property that doesn't exist in label. Remove it.

0
 
LVL 67

Author Comment

by:sirbounty
ID: 17325316
Ok - I started from scratch as you've outlined here.

I went with the harder way and changed it to inherit label.
Then in my New sub, I have the code to pull the username from DirectoryServices.
Saved and built the project, then added the control to a new blank form and ran it.
All it displays is the control's default name - not my username.

I have a try/catch that should set me.text to the 'found' username.
To test, I changed this line to
Me.Text="Working"
but it fails to show even that.
Any ideas?
0
 
LVL 67

Author Comment

by:sirbounty
ID: 17325726
I created a public GetName sub - and it works.
Just curious why it wouldn't on New?
Thanx for the help.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 17407432
No, Chaosian deserves the points.  
I was just waiting in case he cared to follow up on my last comment.
I'll close this out - sorry 'bout the delay...
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question