How can i add A Linklable by calling a function in a class?
-
Hi All Is it Possible to Call A Function Like This to add a link label to a particular form public void AddLinklabel(string form,int top, int left, int width, int height,string Link) { LinkLabel linkLabel1 = new LinkLabel(); form.linkLabel1.Location = new System.Drawing.Point(top, left); form.linkLabel1.Size = new System.Drawing.Size(width, height); form.linkLabel1.AutoSize = true; } If Possible Please Show Me A Example Code Please Help Me
Arunkumar.T ------------------------- p4,3ghz,hdd-500gb,ram-4gb
-
Hi All Is it Possible to Call A Function Like This to add a link label to a particular form public void AddLinklabel(string form,int top, int left, int width, int height,string Link) { LinkLabel linkLabel1 = new LinkLabel(); form.linkLabel1.Location = new System.Drawing.Point(top, left); form.linkLabel1.Size = new System.Drawing.Size(width, height); form.linkLabel1.AutoSize = true; } If Possible Please Show Me A Example Code Please Help Me
Arunkumar.T ------------------------- p4,3ghz,hdd-500gb,ram-4gb
Why not convert your method into a generic method? BTW, please enclose code samples in pre blocks like this:
public void AddLinkLabel<T>(T containingForm, int top, int left, int width, int height, string link) where T : Form
{
LinkLabel label = new LinkLabel();
label.Location = new System.Drawing.Point(top, left);
label.Size = new System.Drawing.Size(width, height);
containingForm.Controls.Add(label);
}Note that I've just typed this sample into this textbox, so there might be an error or two, you should be able to get the gist from this though.
Forgive your enemies - it messes with their heads
My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility
-
Why not convert your method into a generic method? BTW, please enclose code samples in pre blocks like this:
public void AddLinkLabel<T>(T containingForm, int top, int left, int width, int height, string link) where T : Form
{
LinkLabel label = new LinkLabel();
label.Location = new System.Drawing.Point(top, left);
label.Size = new System.Drawing.Size(width, height);
containingForm.Controls.Add(label);
}Note that I've just typed this sample into this textbox, so there might be an error or two, you should be able to get the gist from this though.
Forgive your enemies - it messes with their heads
My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility
I Called The Function Like This But There are lot of errors displaying
Error 1 The type 'string' must be convertible to 'System.Windows.Forms.Form' in order to use it as parameter 'T' in the generic type or method 'WindowsApplication1.Form1.AddLinkLabel<T>(T, int, int, int, int, string)' C:\Documents and Settings\Agni\My Documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\Form1.cs 21 13 WindowsApplication1
AddLinkLabel("Form1", 20, 20, 100, 30, "Click Here");
is there any other method to call this function?
-
I Called The Function Like This But There are lot of errors displaying
Error 1 The type 'string' must be convertible to 'System.Windows.Forms.Form' in order to use it as parameter 'T' in the generic type or method 'WindowsApplication1.Form1.AddLinkLabel<T>(T, int, int, int, int, string)' C:\Documents and Settings\Agni\My Documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\Form1.cs 21 13 WindowsApplication1
AddLinkLabel("Form1", 20, 20, 100, 30, "Click Here");
is there any other method to call this function?
Of course you've got errors, you've given it a string in place of the form instance. You'd need to give it like this:
AddLinkLabel(myFormInstance, 20, 20, 100, 30, "Click here");
BTW - why did you not encode your code in C#? I told you to do it before.
Forgive your enemies - it messes with their heads
My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility
-
Of course you've got errors, you've given it a string in place of the form instance. You'd need to give it like this:
AddLinkLabel(myFormInstance, 20, 20, 100, 30, "Click here");
BTW - why did you not encode your code in C#? I told you to do it before.
Forgive your enemies - it messes with their heads
My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility
Thankyou This Time I Dont Get Any Errors The Program Executed Well But I Cant See The Label I Created And Also How Can I fire Click Event? And Where Should I Add The Url? This is My Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}private void Form1\_Load(object sender, EventArgs e) { Form1 frm1=new Form1(); AddLinkLabel(frm1, 20, 20, 100, 30, "Click Here"); } public void AddLinkLabel<T>(T containingForm, int top, int left, int width, int height, string link) where T : Form { LinkLabel label = new LinkLabel(); label.Location = new System.Drawing.Point(top, left); label.Size = new System.Drawing.Size(width, height); containingForm.Controls.Add(label); } }
}
-
Thankyou This Time I Dont Get Any Errors The Program Executed Well But I Cant See The Label I Created And Also How Can I fire Click Event? And Where Should I Add The Url? This is My Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}private void Form1\_Load(object sender, EventArgs e) { Form1 frm1=new Form1(); AddLinkLabel(frm1, 20, 20, 100, 30, "Click Here"); } public void AddLinkLabel<T>(T containingForm, int top, int left, int width, int height, string link) where T : Form { LinkLabel label = new LinkLabel(); label.Location = new System.Drawing.Point(top, left); label.Size = new System.Drawing.Size(width, height); containingForm.Controls.Add(label); } }
}
You don't need to create a new instance of Form1. In fact, as you have placed this method inside your Form class, you don't even need containingForm, but assuming you are going to move this method into a separate class, your call to AddLinkLabel would look like this:
AddLinkLabel(this, 20, 20, 100, 30, "Click Here");
You have now added the link label to the controls collection of the form that's displayed (and not the form you instantiated in
Form1 frm = new Form1();
.Forgive your enemies - it messes with their heads
My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility
-
You don't need to create a new instance of Form1. In fact, as you have placed this method inside your Form class, you don't even need containingForm, but assuming you are going to move this method into a separate class, your call to AddLinkLabel would look like this:
AddLinkLabel(this, 20, 20, 100, 30, "Click Here");
You have now added the link label to the controls collection of the form that's displayed (and not the form you instantiated in
Form1 frm = new Form1();
.Forgive your enemies - it messes with their heads
My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility
Thankyou For That It Work on a form load event I Writed The Same Code to A Class File To Create a library for link label but it faild there are so many errors displaying this is my class library code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Net;
using System.Windows.Forms;namespace linklabel
{
public class LinkLabel
{public void AddLinkLabel<T>(T containingForm, int top, int left, int width, int height, string Text, string link) where T : Form { LinkLabel label = new LinkLabel(); label.Location = new System.Drawing.Point(top, left); label.Size = new System.Drawing.Size(width, height); label.Text = Text; containingForm.Controls.Add(label); } }
}
is it possible to create a library for a control?
-
Thankyou For That It Work on a form load event I Writed The Same Code to A Class File To Create a library for link label but it faild there are so many errors displaying this is my class library code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Net;
using System.Windows.Forms;namespace linklabel
{
public class LinkLabel
{public void AddLinkLabel<T>(T containingForm, int top, int left, int width, int height, string Text, string link) where T : Form { LinkLabel label = new LinkLabel(); label.Location = new System.Drawing.Point(top, left); label.Size = new System.Drawing.Size(width, height); label.Text = Text; containingForm.Controls.Add(label); } }
}
is it possible to create a library for a control?
Arunkumar.Koloth wrote:
is it possible to create a library for a control?
Yes, but you have to remember to add the right references to the class library. Here's a hint for you for the future; when I want to create a library for a forms application like this I would normally create it as a windows forms application, remove the generated forms, and change the output type to class library. By doing this, I've got all the basic references that I need. From this answer, you can tell that what you need to do is add in the missing references. Good luck:thumbsup:
Forgive your enemies - it messes with their heads
My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility
-
Arunkumar.Koloth wrote:
is it possible to create a library for a control?
Yes, but you have to remember to add the right references to the class library. Here's a hint for you for the future; when I want to create a library for a forms application like this I would normally create it as a windows forms application, remove the generated forms, and change the output type to class library. By doing this, I've got all the basic references that I need. From this answer, you can tell that what you need to do is add in the missing references. Good luck:thumbsup:
Forgive your enemies - it messes with their heads
My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility
Thankyou
Arunkumar.T
-
Thankyou
Arunkumar.T
You're welcome.
Forgive your enemies - it messes with their heads
My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility