|
Your going to have to be a bit more clear as to what you mean.
At design-time, all you do is add your custom control to the Toolbox, then drag it to the Form as many times as you need.
To add your control, right-click in the Toolbox and pick "Add/Remove Items..."
There is no such thing as a control array in the .NET Framework. It must be simulated, but can only be done at run-time, not design-time. See Creating Control Arrays in Visual Basic .NET and Visual C# .NET[^] on MSDN.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
thank you for reply and sorry my bad english,
i have about 60 controls in a form (its a touchscreen application) and i want to load values for different styles (backgroundcolor,...) from a mysql database.
my problem is to assign this database values to the controls. I think the easiest way ist to create a database with a id-number, and each id number (= control index) has a value for backcolor, textsize,.... and this values are loaded at startup in my control-array.
But the position and size of the controls should be set in design-time, because its much easier to create a good layout.
Or is it possible to access the control attributes and methods through a string variable, so i could use a database like this:
Name;color;textsize
button1;red;10
button2;blue;12
button2;green;10
......
Thanks
Mike
|
|
|
|
|
Wow, 60?! It can be done using the Form.Controls collection. You can specify the index on that collection, but your going to run into a couple of problems.
First, if you make change to the visual properties of most of your controls, you'll find that the method you want to use will be slow. Actually, any method will be slow... So try out your method first before you dump alot of time into depending on it. See if the performance is going to be acceptable for you.
Second, your database that hold all the changes in not going to be linked directly to your controls, so ANY changes to the controls on the form, like accidently deleting and readding a control, will change the index of the control. This will make future versions of your application a [explitive deleted] to write.
Instead of relying on the index of the control, what you might want to do is add data to the .Tag property of your controls that uniquely identifies each of them. Then, use that as an indentifier in your database with the changes to be made to them. When you need to make changes, you'll have to iterate through the controls, checking each controls .Tag property for the ID of the control you want, then make the change to it. This will be even slower that using the index method, but will be far more reliable when making changes to your form.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thank you,
i think i try it with the tag property
greetings
mike
|
|
|
|
|
I have a ComboBox and I’m giving it a Class cCompany not just a string.
public class cCompany
{
public string sz_Name;
public string sz_Address;
public cCompany(string Name, string Address)
{
sz_Name = Name;
sz_Address = Address;
}
public cCompany(cCompany obj)
{
sz_Name=obj.sz_Name;
sz_Address = obj.sz_Address;
}
public override string ToString()
{
return sz_Name;
}
}
In the ComboBox one types the name of the company and there is a TextBox where one types the address.
My way of thinking is that this line
this.cbToCompany.Items[index].sz_Address=this.tbToAddress.Text;
should compile but the .sz_Address gives this error:
'object' does not contain a definition for 'sz_Address'
I’m a beginner C# programmer and until now I’ve found the language very intuitive. Pleas help.
Ronald Hahn, CNT - Computer Engineering Technologist
New Technologies Analyst
|
|
|
|
|
See u have sz_Address in the class onl. But that property not exist in the combobox item[index] property.
U can find it out more easyly. After tying this.cbToCompany.Items[index] whne u will press "." after that did u find sz_Address. if u'r finding it is ok. If not place
this.cbToCompany.Items[index].add=this.tbToAddress.Text;
i think this may work out.
Bye
Arun Kumar Sabat
|
|
|
|
|
The ComboBox.Items property is a ObjectCollection, so that this code snippet this.cbToCompany.Items[index] returns an instance of type Object. To use it the way you want you'll have to cast the instance first:
( (cCompany) this.cbToCompany.Items[index]).sz_Address=this.tbToAddress.Text;
If you use this be sure your ComboBox contains only instances of type cCompany cause otherwise an exception will be raised.
www.troschuetz.de
|
|
|
|
|
Thanks,
That worked perfactly!
Ronald Hahn, CNT - Computer Engineering Technologist
New Technologies Analyst
HahnTech Affiliated With Code Constructors
12029 45 Street N.W.
Edmonton, Alberta, Canada T5W 2T7
Res. Ph: (780) 695.5589
Email: rhahn82@telus.net
|
|
|
|
|
Hi~
Can I export a class written in C++ in dll to C#? That means can I use the class C++ dll to declare objects in C#?
Thanks
|
|
|
|
|
Yes you can. This[^] should get you up to speed.
Paul Lyons, CCPL Certified Code Project Lurker
|
|
|
|
|
Actually it won't. Interop'ing native classes (i.e., not COM components) is not covered in the tutorial. There is some vague documentation in the CallingConvention enumeration, though.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
|
Next question is:
I found some stuff to enumerate the GAC, but what I want is something that looks more like VS's Add Reference dialog. There are two interesting things going on in this list:
1. It shows the path to the installed assembly, not the GAC path
2. It only shows assemblies relevant to the current compiler version.
How the heck does it do that? I've looked around for a couple months, off and on, and have never found the answer!
Marc
MyXaml
Advanced Unit Testing
|
|
|
|
|
It has nothing to do with the GAC. See the registry key HKEY_LOCAL_MACHINE\Software\Microsoft\.NETFramework\AssemblyFolders .
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Heath Stewart wrote:
See the registry key HKEY_LOCAL_MACHINE\Software\Microsoft\.NETFramework\AssemblyFolders.
I hope I'm not asking a really dumb question here--I have entries in that registry key, but there's no "data"--only folders with the names of the assemblies.
So, the question is, how do I take that information and obtain the actual assembly path?
Thanks!
Marc
MyXaml
Advanced Unit Testing
|
|
|
|
|
Enumerate the sub-keys and grab the default value of each sub-key. Enumerate each directory to load the assemblies:
using System;
using System.IO;
using Microsoft.Win32;
class Test
{
static void Main()
{
using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(
@"Software\Microsoft\.NETFramework\AssemblyFolders"))
{
foreach (string key in rk.GetSubKeyNames())
{
using (RegistryKey af = rk.OpenSubKey(key))
{
string dir = (string)af.GetValue(null);
if (Directory.Exists(dir))
{
Console.WriteLine("Enumerating \"{0}\"...", dir);
foreach (string file in Directory.GetFiles(dir, "*.dll"))
{
Console.WriteLine(file);
}
Console.WriteLine();
}
}
}
}
}
} If you want to check the version of the runtime the assembly uses, you could load it and see which version of mscorlib.dll is required. If this application will be running for a while (like Visual Studio), then you should consider creating a new AppDomain to do this since you cannot unload assemblies and don't want to have all those assemblies loaded for no reason.
Instead of loading the assemblies, you could also load the PE/COFF images and determine the information yourself. You could use IL Reader[^] (from Lutz Roeder, creator of .NET Reflector) to inflect what that could be and not load the assembly into an AppDomain at all.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Oh God, I'm an idiot. I had the data name column set so wide on my registry view that I didn't even see that the default value had any content.
Major embarassment here.
Thanks for the other feedback regarding figuring out what version of mscorlib.dll is required. That's definitely something I didn't realize!
Marc
MyXaml
Advanced Unit Testing
|
|
|
|
|
Is it possible for a dll to call dll? What I'm doing is creating few dll, along with one standard.dll. For example, those dlls (111.dll, 222.dll, 333.dll, 444.dll, 555.dll) would call a single function from standards.dll. So that the function in standard.dll would be consistent with those 5 dlls. It will save time rather than having to recompile all of those 5 dlls after revising the standard.dll.
I have created the application which passes the string variable over to the dll then one of those 5 dll would be used (depending on the data). I hope that I have explained clearly.
I've been using Visual.Net C# language to do this. I am able to communicate with one of those 5 dlls, but unsure how to do this to have one of 5 dlls to communicate with standards.dll. I am also hoping to have standard.dll to be separate from those 5 (not to be built in but separeate.)
|
|
|
|
|
DLLs don't "call" other DLLs, but they do reference them. Assemblies can reference each other, and you can even have circular references (it's very tricky, though, and requires pretty good knowledge of the DLLs - but Types can't be circular), but not in Visual Studio .NET.
Your types in other DLLs (assemblies are what they actually are in .NET) must be public in order for Types in other assemblies to use them. This is no different than when you reference assemblies from the Base Class Library (BCL), like System.Windows.Forms.Form for Windows Forms, or System.Web.UI.WebControls.Control for ASP.NET web controls.
Using VS.NET, you can add references to .NET assemblies, COM libraries, and even other projects in the same solution. Right-click on your project and select Add Reference. Use project references when possible (with multi-project solutions) to establish build dependencies.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
The poor guy is probably trying to do some type of plugin architecture... maybe couldn't express himself correctly.
In that case he can start digging through Reflections
|
|
|
|
|
I've got it!
I've used the dll's (not the standards.dll) to be called by late binding of dll's (see sample code below
----
String PassToDll("FFEEFF1A");
String path = "abc.dll";
Assembly a = Assembly.LoadFrom(path);
Type mm = a.GetType("abc");
object o = Activator.CreateInstance(mm);
object [] par = new object[] {PassToDll};
edtDllResult.Text = mm.InvokeMember("InterpretCrumData", BindingFlags.Default | BindingFlags.InvokeMethod, null, o, par).ToString();
----
then I created abc.dll by creating a new library. I added the reference for Standards.dll.
then sample code in abc.dll
----
using System;
using Standards_Dll;
//namespace abc_Dll
//{
///
/// Summary description for Class1.
///
public class abc
{
public abc()
{ // TODO: Add constructor logic here // }
public int InterpretCrumData(string readtext)
{
// snip code
return (<variable>);
}
}
// }
----
So now I am able to make more dll's for this.
|
|
|
|
|
hey all,
I'm somewhat new to C# programming. Basically I want to send the current day that the program is executed on (Monday, Tues, Etc.) to a variable, and then to a text box (textBox1). here is what I have so far to run when the form loads.
if (day = DateTime.Today.DayOfWeek.Equals(Monday))<br />
this.textBox1.Text = "It is Monday!";<br />
else<br />
{<br />
}
I also added the namespace (I think its called)
private System.DateTime day;
so what's wrong with the code? any help would be awesome.
I know I have a lot of learning ahead, so don't worry about the criticisms
happy programming,
Stephen
|
|
|
|
|
I think what you want is:
if (DateTime.Today.DayOfWeek==DayOfWeek.Monday)
{
...
}
There's no reason to use "Equals", but if you want to, you probably have to say "Equals(DayOfWeek.Monday)" to properly reference the enumerator.
Also, the "day=" assignment doesn't make any sense. Is "day" a boolean? Because that's what the Equals returns.
Marc
MyXaml
Advanced Unit Testing
|
|
|
|
|
awesome, thanks a lot for the help.
-Stephen
|
|
|
|
|
just a thought (not at a computer with a programming environment atm)
Does this work:
<br />
this.textBox1.Text = "It is " + DateTime.Today.DayOfWeek.ToString() + "!";<br />
(You'll probably have to fiddle syntax, as that's just off the top of my head)
I've noticed all these ToString members everywhere - dunno if it'd work properly with an enum like that, but it seems to be what it's intended for!
--
Help me! I'm turning into a grapefruit!
Phoenix Paint - back from DPaint's ashes!
|
|
|
|