Inserting User Control in a project

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 3725 Views - Last Post: 20 February 2011 - 09:29 AM Rate Topic: -----

#1 Ahmedn1   User is offline

  • D.I.C Addict
  • member icon

Reputation: 24
  • View blog
  • Posts: 564
  • Joined: 04-August 09

Inserting User Control in a project

Posted 19 February 2011 - 10:08 AM

I have created a user control to use in my application
but I need to let the user control its opacity
I searched the web a lot but all the codes I tried didn't work
so I inherited the control from System.Windows.Forms so I can use its built-in Opacity property

I completed the control
but when I tried to run the project
I got an exception telling that there is no user control in the project

i guess that is because it didn't inherit from UserControl class

so what should I do?

Is This A Good Question/Topic? 0
  • +

Replies To: Inserting User Control in a project

#2 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6536
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Inserting User Control in a project

Posted 19 February 2011 - 10:12 AM

Quote

I got an exception telling that there is no user control in the project

That's not what the error said. Please tell us the actual error without rephrasing it.

Quote

so what should I do?

Show us your actual code where you are trying to implement an instance of your control, along with the control itself.
Was This Post Helpful? 0
  • +
  • -

#3 Ahmedn1   User is offline

  • D.I.C Addict
  • member icon

Reputation: 24
  • View blog
  • Posts: 564
  • Joined: 04-August 09

Re: Inserting User Control in a project

Posted 19 February 2011 - 10:25 AM

Details:
namespace: StopWatch
control class: StopWatch
Main program class: StopWatch_system

here is the calling code from my program's main form

StopWatch.StopWatch st = new StopWatch.StopWatch("Laptop", "");
            st.Show();



StopWatch (namespace) . StopWatch (control class)

here is part of the control class

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Hotkeys;
using System.IO;

namespace StopWatch
{
    public partial class StopWatch : Form
    {
        public StopWatch()
        {
            InitializeComponent();
            lblName.Text = "Timer";
        }

        public StopWatch(string dev, string path)
        {
            InitializeComponent();
            Options.DevName = dev;
            Options.imagePath = path;
            logo.Image = Image.FromFile(Options.imagePath);
            lblName.Text = Options.DevName;
        }



and this is the error

[quote]
Assembly 'C:\Users\Ahmedn1\Documents\Visual Studio 2008\Projects\StopWatch\StopWatch\obj\Release\StopWatch.dll' doesn't contain any UserControl types.
[quote]
Was This Post Helpful? 0
  • +
  • -

#4 [email protected]   User is offline

  • D.I.C Addict
  • member icon

Reputation: 1003
  • View blog
  • Posts: 975
  • Joined: 30-September 10

Re: Inserting User Control in a project

Posted 19 February 2011 - 10:30 AM

Stop watch isn't a UserControl. It is a Form. It needs to derive from the UserControl class to be a UserControl :).

EDIT: didn't read the whole of the OP...sorry ;)

This post has been edited by [email protected]: 19 February 2011 - 10:41 AM

Was This Post Helpful? 1
  • +
  • -

#5 jayfella   User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 24
  • Joined: 07-March 09

Re: Inserting User Control in a project

Posted 19 February 2011 - 11:29 AM

playing around with opacities in WinForms isnt really a great idea. Im sure there are millions of ways, but this could easily be achieved in WPF in a few characters.

Anyway.

Im not really sure why you would want to control the opacity, but there may be an alternative in setting the visibility or even taking a "sidestep" approach and using the .BringToFront() and .SendToBack() abilities of the controls. Other than that you could possibly "fake" the opacity and change the color of the foreground in a little loop.

To summarize, opacities arent a great thing to play with on WinForms. It can be tricky.
Was This Post Helpful? 0
  • +
  • -

#6 Ahmedn1   User is offline

  • D.I.C Addict
  • member icon

Reputation: 24
  • View blog
  • Posts: 564
  • Joined: 04-August 09

Re: Inserting User Control in a project

Posted 19 February 2011 - 12:16 PM

so no other way to change the opacity of the user control?
Was This Post Helpful? 0
  • +
  • -

#7 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6536
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Inserting User Control in a project

Posted 19 February 2011 - 12:33 PM

http://www.codeproje...pTutorial3.aspx
Was This Post Helpful? 0
  • +
  • -

#8 Ahmedn1   User is offline

  • D.I.C Addict
  • member icon

Reputation: 24
  • View blog
  • Posts: 564
  • Joined: 04-August 09

Re: Inserting User Control in a project

Posted 19 February 2011 - 02:05 PM

View PosttlhIn`toq, on 19 February 2011 - 12:33 PM, said:



but these all are based on form
Was This Post Helpful? 0
  • +
  • -

#9 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6536
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Inserting User Control in a project

Posted 19 February 2011 - 05:25 PM

View PostAhmedn1, on 19 February 2011 - 03:05 PM, said:

View PosttlhIn`toq, on 19 February 2011 - 12:33 PM, said:



but these all are based on form


So what's the problem? That's what your DLL is creating.

Quote

public partial class StopWatch : Form


I thought you got that several posts ago.

You need to fix something somewhere so you are consistantly either referring to a UserControl or a Form. Pick one. Your DLL is already coded to make a form, and a form is what you need to have variable opacity. So again I ask, what's the problem?
Was This Post Helpful? 0
  • +
  • -

#10 Ahmedn1   User is offline

  • D.I.C Addict
  • member icon

Reputation: 24
  • View blog
  • Posts: 564
  • Joined: 04-August 09

Re: Inserting User Control in a project

Posted 19 February 2011 - 05:28 PM

the problem is not about the form opacity

I handle it fine

the problem is I can not build this dll because it has not any user control class
Was This Post Helpful? 0
  • +
  • -

#11 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6536
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Inserting User Control in a project

Posted 19 February 2011 - 06:02 PM

View PostAhmedn1, on 19 February 2011 - 06:28 PM, said:

the problem is not about the form opacity

I handle it fine

the problem is I can not build this dll because it has not any user control class


Then you have to fix it in your DLL, as you have already been told.

[email protected] said:

Stop watch isn't a UserControl. It is a Form. It needs to derive from the UserControl class to be a UserControl .


Quote

public partial class StopWatch : Form



This needs to inherit from UserControl not from Form.
public partial class StopWatch : UserControl



And you will need to fix all the little things that go with that like

public StopWatch()
        {
            InitializeComponent(); // This does not exist in a UserControl
            lblName.Text = "Timer";
        }


This post has been edited by tlhIn`toq: 19 February 2011 - 06:03 PM

Was This Post Helpful? 0
  • +
  • -

#12 Ahmedn1   User is offline

  • D.I.C Addict
  • member icon

Reputation: 24
  • View blog
  • Posts: 564
  • Joined: 04-August 09

Re: Inserting User Control in a project

Posted 19 February 2011 - 06:08 PM

I thought about that
but then I return again to the same problem
I cannot control opacity in a user control
Was This Post Helpful? 0
  • +
  • -

#13 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6536
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Inserting User Control in a project

Posted 19 February 2011 - 06:15 PM

View PostAhmedn1, on 19 February 2011 - 07:08 PM, said:

I thought about that
but then I return again to the same problem
I cannot control opacity in a user control


Riiiiiight. That's what we have been saying all along: You have to pick one or the other. It's either a UserControl or you can play with the opacity.

Let me ask you this, how important is it that this be a UserControl? I mean, really, as a usercontrol its going to get dropped on top of a form anyway.

It's starting to sound like you want to have this stopwatch on top of a game screen or picture box or something. If you are trying to use a UserControl as a way of avoid a custom drawing function then you are going the wrong way around.

So how about this... Tell us what the actual goal is for this stopwatch and we can tell you if form or UserControl is even near the right approach.
Was This Post Helpful? 0
  • +
  • -

#14 Ahmedn1   User is offline

  • D.I.C Addict
  • member icon

Reputation: 24
  • View blog
  • Posts: 564
  • Joined: 04-August 09

Re: Inserting User Control in a project

Posted 19 February 2011 - 06:33 PM

I know what you mean
you mean I can use just a form as the stopwatch without the need to create a dll for the control

but the purpose is that the application allows the user to create many stopwatches for different goals
and handle them all

that's the reason I need it to be a dll so I can create instances from the same application
Was This Post Helpful? 0
  • +
  • -

#15 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6536
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Inserting User Control in a project

Posted 19 February 2011 - 06:52 PM

View PostAhmedn1, on 19 February 2011 - 07:33 PM, said:

that's the reason I need it to be a dll so I can create instances from the same application


Someone told you that you had to put your component into a DLL in order to make more than one instance of the class? Slap the stupid right off of whomever told you that.

Do the tutorials. You'll see this is by no means the case.


Bulding an application - Part 1
Building an application - Part 2
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2