|
Hi, I generate code (codigo) dinamcally and then complile it in memory for showit in propertyGrid
<br />
parametros.ReferencedAssemblies.Add("System.dll");<br />
parametros.ReferencedAssemblies.Add("System.Data.dll");<br />
parametros.ReferencedAssemblies.Add("System.Design.dll");<br />
parametros.GenerateInMemory = true;<br />
CompilerResults compilado = compilador.CompileAssemblyFromSource(parametros,codigo);<br />
The class made has inset classes of custom stringconverter for asssig enums to properyies and show in combo way.
<br />
this.Objeto = ensambaldo.CreateInstance("miNamespace.miClase",false,BindingFlags.CreateInstance,null,new object[]{this.DS.Tables[0].Rows[0]},System.Globalization.CultureInfo.CurrentCulture,null);<br />
Then I copy the code and paste to a fisical class.cs and compile the project and make an instance of myClass
I show the objects int PropertyGrid These objets
The object that made dianmically not show the combo feature in the properties but in the object made with the fisical file show the properties with the combo - enum feature, this one works fine.
What diferense can be have the two ways of make an object,
This is the Class:
<br />
<br />
using System;<br />
using System.Data;<br />
using System.ComponentModel;<br />
using System.Reflection;<br />
<br />
namespace miNamespace <br />
{<br />
public class miClase <br />
{<br />
<br />
private System.Data.DataRow m_Row = null;<br />
public static string[] Table1s = new string[4];<br />
public System.Collections.Hashtable ColCustomerID = new System.Collections.Hashtable();<br />
public System.Collections.Hashtable _ColCustomerID = new System.Collections.Hashtable();<br />
public static string[] Table2s = new string[9];<br />
public System.Collections.Hashtable ColEmployeeID = new System.Collections.Hashtable();<br />
public System.Collections.Hashtable _ColEmployeeID = new System.Collections.Hashtable();<br />
public miClase(System.Data.DataRow row)<br />
{<br />
m_Row = row;<br />
<br />
Table1s[0] = "Alfreds Futterkiste";<br />
ColCustomerID.Add("ALFKI","Alfreds Futterkiste");<br />
_ColCustomerID.Add("Alfreds Futterkiste","ALFKI");<br />
Table1s[1] = "Ana Trujillo Emparedados y helados";<br />
ColCustomerID.Add("ANATR","Ana Trujillo Emparedados y helados");<br />
_ColCustomerID.Add("Ana Trujillo Emparedados y helados","ANATR");<br />
Table1s[2] = "Antonio Moreno Taquería";<br />
ColCustomerID.Add("ANTON","Antonio Moreno Taquería");<br />
_ColCustomerID.Add("Antonio Moreno Taquería","ANTON");<br />
Table1s[3] = "Around the Horn";<br />
ColCustomerID.Add("AROUT","Around the Horn");<br />
_ColCustomerID.Add("Around the Horn","AROUT");<br />
<br />
Table2s[0] = "Davolio, Nancy";<br />
ColEmployeeID.Add("1","Davolio, Nancy");<br />
_ColEmployeeID.Add("Davolio, Nancy","1");<br />
Table2s[1] = "Fuller, Andrew";<br />
ColEmployeeID.Add("2","Fuller, Andrew");<br />
_ColEmployeeID.Add("Fuller, Andrew","2");<br />
Table2s[2] = "Leverling, Janet";<br />
ColEmployeeID.Add("3","Leverling, Janet");<br />
_ColEmployeeID.Add("Leverling, Janet","3");<br />
Table2s[3] = "Peacock, Margaret";<br />
ColEmployeeID.Add("4","Peacock, Margaret");<br />
_ColEmployeeID.Add("Peacock, Margaret","4");<br />
Table2s[4] = "Buchanan, Steven";<br />
ColEmployeeID.Add("5","Buchanan, Steven");<br />
_ColEmployeeID.Add("Buchanan, Steven","5");<br />
Table2s[5] = "Suyama, Michael";<br />
ColEmployeeID.Add("6","Suyama, Michael");<br />
_ColEmployeeID.Add("Suyama, Michael","6");<br />
Table2s[6] = "King, Robert";<br />
ColEmployeeID.Add("7","King, Robert");<br />
_ColEmployeeID.Add("King, Robert","7");<br />
Table2s[7] = "Callahan, Laura";<br />
ColEmployeeID.Add("8","Callahan, Laura");<br />
_ColEmployeeID.Add("Callahan, Laura","8");<br />
Table2s[8] = "Dodsworth, Anne";<br />
ColEmployeeID.Add("9","Dodsworth, Anne");<br />
_ColEmployeeID.Add("Dodsworth, Anne","9");<br />
<br />
if(row["OrderID"] != DBNull.Value)<br />
{<br />
this.OrderID = (System.Int32)row["OrderID"];<br />
}<br />
if(row["CustomerID"] != DBNull.Value)<br />
{<br />
if(ColCustomerID[row["CustomerID"]] != null)<br />
{<br />
this.CompanyName = (string)ColCustomerID[row["CustomerID"]];<br />
}<br />
}<br />
if(row["EmployeeID"] != DBNull.Value)<br />
{<br />
if(ColEmployeeID[row["EmployeeID"]] != null)<br />
{<br />
this.Name = (string)ColEmployeeID[row["EmployeeID"]];<br />
}<br />
}<br />
if(row["OrderDate"] != DBNull.Value)<br />
{<br />
this.OrderDate = (System.DateTime)row["OrderDate"];<br />
}<br />
if(row["RequiredDate"] != DBNull.Value)<br />
{<br />
this.RequiredDate = (System.DateTime)row["RequiredDate"];<br />
}<br />
if(row["ShippedDate"] != DBNull.Value)<br />
{<br />
this.ShippedDate = (System.DateTime)row["ShippedDate"];<br />
}<br />
if(row["ShipVia"] != DBNull.Value)<br />
{<br />
this.ShipVia = (System.Int32)row["ShipVia"];<br />
}<br />
if(row["Freight"] != DBNull.Value)<br />
{<br />
this.Freight = (System.Decimal)row["Freight"];<br />
}<br />
if(row["ShipName"] != DBNull.Value)<br />
{<br />
this.ShipName = (System.String)row["ShipName"];<br />
}<br />
if(row["ShipAddress"] != DBNull.Value)<br />
{<br />
this.ShipAddress = (System.String)row["ShipAddress"];<br />
}<br />
if(row["ShipCity"] != DBNull.Value)<br />
{<br />
this.ShipCity = (System.String)row["ShipCity"];<br />
}<br />
if(row["ShipRegion"] != DBNull.Value)<br />
{<br />
this.ShipRegion = (System.String)row["ShipRegion"];<br />
}<br />
if(row["ShipPostalCode"] != DBNull.Value)<br />
{<br />
this.ShipPostalCode = (System.String)row["ShipPostalCode"];<br />
}<br />
if(row["ShipCountry"] != DBNull.Value)<br />
{<br />
this.ShipCountry = (System.String)row["ShipCountry"];<br />
}<br />
}<br />
private System.Int32 m_OrderID;<br />
<br />
public System.Int32 OrderID<br />
{<br />
get { return m_OrderID; }<br />
set <br />
{ <br />
m_OrderID = value;m_Row["OrderID"] = value;<br />
}<br />
}<br />
<br />
private string m_CompanyName;<br />
[Browsable(true)][TypeConverter(typeof(Table1Converter))]<br />
public string CompanyName<br />
{<br />
get { return m_CompanyName; }<br />
set <br />
{ <br />
m_CompanyName = value;m_Row["CustomerID"] = _ColCustomerID[value];<br />
}<br />
}<br />
<br />
private string m_Name;<br />
[Browsable(true)][TypeConverter(typeof(Table2Converter))]<br />
public string Name<br />
{<br />
get { return m_Name; }<br />
set <br />
{ <br />
m_Name = value;m_Row["EmployeeID"] = _ColEmployeeID[value];<br />
}<br />
}<br />
<br />
private System.DateTime m_OrderDate;<br />
<br />
public System.DateTime OrderDate<br />
{<br />
get { return m_OrderDate; }<br />
set <br />
{ <br />
m_OrderDate = value;m_Row["OrderDate"] = value;<br />
}<br />
}<br />
<br />
private System.DateTime m_RequiredDate;<br />
<br />
public System.DateTime RequiredDate<br />
{<br />
get { return m_RequiredDate; }<br />
set <br />
{ <br />
m_RequiredDate = value;m_Row["RequiredDate"] = value;<br />
}<br />
}<br />
<br />
private System.DateTime m_ShippedDate;<br />
<br />
public System.DateTime ShippedDate<br />
{<br />
get { return m_ShippedDate; }<br />
set <br />
{ <br />
m_ShippedDate = value;m_Row["ShippedDate"] = value;<br />
}<br />
}<br />
<br />
private System.Int32 m_ShipVia;<br />
<br />
public System.Int32 ShipVia<br />
{<br />
get { return m_ShipVia; }<br />
set <br />
{ <br />
m_ShipVia = value;m_Row["ShipVia"] = value;<br />
}<br />
}<br />
<br />
private System.Decimal m_Freight;<br />
<br />
public System.Decimal Freight<br />
{<br />
get { return m_Freight; }<br />
set <br />
{ <br />
m_Freight = value;m_Row["Freight"] = value;<br />
}<br />
}<br />
<br />
private System.String m_ShipName;<br />
<br />
public System.String ShipName<br />
{<br />
get { return m_ShipName; }<br />
set <br />
{ <br />
m_ShipName = value;m_Row["ShipName"] = value;<br />
}<br />
}<br />
<br />
private System.String m_ShipAddress;<br />
<br />
public System.String ShipAddress<br />
{<br />
get { return m_ShipAddress; }<br />
set <br />
{ <br />
m_ShipAddress = value;m_Row["ShipAddress"] = value;<br />
}<br />
}<br />
<br />
private System.String m_ShipCity;<br />
<br />
public System.String ShipCity<br />
{<br />
get { return m_ShipCity; }<br />
set <br />
{ <br />
m_ShipCity = value;m_Row["ShipCity"] = value;<br />
}<br />
}<br />
<br />
private System.String m_ShipRegion;<br />
<br />
public System.String ShipRegion<br />
{<br />
get { return m_ShipRegion; }<br />
set <br />
{ <br />
m_ShipRegion = value;m_Row["ShipRegion"] = value;<br />
}<br />
}<br />
<br />
private System.String m_ShipPostalCode;<br />
<br />
public System.String ShipPostalCode<br />
{<br />
get { return m_ShipPostalCode; }<br />
set <br />
{ <br />
m_ShipPostalCode = value;m_Row["ShipPostalCode"] = value;<br />
}<br />
}<br />
<br />
private System.String m_ShipCountry;<br />
<br />
public System.String ShipCountry<br />
{<br />
get { return m_ShipCountry; }<br />
set <br />
{ <br />
m_ShipCountry = value;m_Row["ShipCountry"] = value;<br />
}<br />
}<br />
<br />
<br />
public class Table1Converter : StringConverter<br />
{<br />
<br />
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)<br />
{<br />
return true;<br />
}<br />
<br />
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)<br />
{<br />
return true;<br />
}<br />
<br />
public override<br />
System.ComponentModel.TypeConverter.StandardValuesCollection<br />
GetStandardValues(ITypeDescriptorContext context)<br />
{<br />
return new StandardValuesCollection(Table1s);<br />
}<br />
<br />
}<br />
<br />
public class Table2Converter : StringConverter<br />
{<br />
<br />
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)<br />
{<br />
return true;<br />
}<br />
<br />
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)<br />
{<br />
return true;<br />
}<br />
<br />
public override<br />
System.ComponentModel.TypeConverter.StandardValuesCollection<br />
GetStandardValues(ITypeDescriptorContext context)<br />
{<br />
return new StandardValuesCollection(Table2s);<br />
}<br />
<br />
}<br />
}}<br />
La realidad no es más que impulsos eléctricos del cerebro - Morpheus
|
|
|
|
|
I have some problem is C# -- in my program :
I will do transperment for label -- ???
i'am add picture to main form and in this picture i draw or write
some statement .. i want to coverd by trans. label ...???
Can You Help Me .... Please !!!
|
|
|
|
|
Umm... I don't really understand what you are trying to tell me here. Can u try and explain a bit more detailed?
Regards,
Polis
Can you practice what you teach?
|
|
|
|
|
in simple statement :
I want Diaphanousness or Limpidness or Pellucid or Transparence label
|
|
|
|
|
Well, if all you want is a transparent label, you can set its background property to Transparent, either through the IDE or programmatically.
Hope this helps
Regards,
Polis
Can you practice what you teach?
|
|
|
|
|
Hi,
I execute a command from inside my C# program. So the cmd window comes up when the processing realted to the command window is in execution.
How do I hide the window programmatically?
Here is what i do to execute the command from within the code.....
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo = new System.Diagnostics.ProcessStartInfo(command, commandLineArg);
process.Start();
Pls reply asap!
Thanks,
Sheela
|
|
|
|
|
I have not tried this, but...
There are StandardError , StandardInput and StandardOutput streams properties on a Process . If you were to assign your own streams to those properties, it should/could/may cause the window to not display.
my blog
|
|
|
|
|
In your ProcessStartInfo object, try setting the WindowStyle property to Hidden before you start your process.
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo = new System.Diagnostics.ProcessStartInfo(command, commandLineArg);
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
process.Start();
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
This helped... thanks!
|
|
|
|
|
My English is not good.. if you can't understand,sorry..
I want to change value in resource of c# windows application from other application.
if my application is c++, I can use UpdateResource() of win32API.
But my application is c#. What do i have to do??
Please help me!!!!!
|
|
|
|
|
Hi, I have 2 questions:
1) I have a string with a full path to a file and I want to open a folder the file is in.
2) I have a system tray icon, when I right-click it i can choose to close the app or to show the full window. How do I do it so double click opens the window too?
Thanks for any answers!
|
|
|
|
|
Anonymous wrote:
1) I have a string with a full path to a file and I want to open a folder the file is in.
I am not sure about this one. A google search should give u the answer relatively easy.
Anonymous wrote:
2) I have a system tray icon, when I right-click it i can choose to close the app or to show the full window. How do I do it so double click opens the window too?
U have to handle the double-click event for the notify icon. Within this event you could say something like:
this.Show();
WindowState = FormWindowState.Normal;
Regards,
Polis
Can you practice what you teach?
|
|
|
|
|
Hi!
1) You can simply call Process.Start("explorer.exe", pathToShow); .
2) The NotifyIcon does have a DoubleClick event, according to the documentation.
Regards,
mav
|
|
|
|
|
Currently I'm creating a c# app to extract data from a vendor specific text file and export it to an Access database.
OK, so I've created a DataSet with a DataTable in it, extracted the data from the file into the DataTable and now I'm trying to squirt this data into a table in the target database using a DataAdapter.
The target table has one key field defined within it.
If the table is empty all works as it should do, however if there is data already in the table the DataAdapter attempts to use an Insert command to update the data (when I think it should be issuing an Update command) and throws an error saying it would create duplicate keys.
And so the question.....
What method does the DataAdapter use to determine if the record being updated is new or changed? Does it look only at the key fields? or all fields?
Yours Despairingly
Simon
|
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
public struct JOB_INFO_1
{
public long JobId;
[MarshalAs(UnmanagedType.LPTStr)]public string pPrinterName;
[MarshalAs(UnmanagedType.LPTStr)]public string pMachineName;
[MarshalAs(UnmanagedType.LPTStr)]public string pUserName;
[MarshalAs(UnmanagedType.LPTStr)]public string pDocument;
[MarshalAs(UnmanagedType.LPTStr)]public string pDatatype;
//public string pStatus;
[MarshalAs(UnmanagedType.LPTStr)] public string pStatus;
public long Status;
public long Priority;
public long Position;
public long TotalPages;
public long PagesPrinted;
public SYSTEMTIME Submitted;
}
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEMTIME
{
public int wYear;
public int wMonth;
public int wDayOfWeek;
public int wDay;
public int wHour;
public int wMinute;
public int wSecond;
public int wMilliseconds;
}
[DllImport("winspool.drv", CharSet=CharSet.Auto)]
public static extern bool OpenPrinter( string pPrinterName, out IntPtr
phPrinter, IntPtr pDefault );
[DllImport("winspool.drv", CharSet=CharSet.Auto)]
public static extern bool ClosePrinter( IntPtr hPrinter);// handle to printer
[DllImport("winspool.drv", CharSet=CharSet.Auto)]
public static extern int EnumJobs( IntPtr hPrinter, int FirstJob, int
NoJobs, int Level, IntPtr pInfo, int cdBuf, out int pcbNeeded, out int
pcReturned);
[SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.UnmanagedCode)]
public void JobsInPrinter(string Printer)
{
IntPtr handle;
int FromJob = 0;
int ToJobs = 100;
int pcbNeeded;
int pcReturned;
// open printer
OpenPrinter (Printer, out handle, IntPtr.Zero );
// get num bytes required
EnumJobs ( handle, FromJob, ToJobs, 1, IntPtr.Zero, 0, out pcbNeeded, out pcReturned);
if(pcbNeeded > 0)
{
// allocate unmanaged memory
IntPtr pData = Marshal.AllocHGlobal ( pcbNeeded );
// get structs
EnumJobs ( handle, FromJob,ToJobs, 1, pData, pcbNeeded, out pcbNeeded, out pcReturned);
// create array of managed job structs
JOB_INFO_1 [] jobs = new JOB_INFO_1[pcReturned];
// marshal struct to managed
int pTemp = pData.ToInt32(); //start pointer
for (int i=0; i
|
|
|
|
|
I am trying to figure out the best way to pass connection information to a spawned thread after accepting a socket connection. I know that the listener information is perishable and I want to eliminate the risk of losing the connection information. Here is what I am doing.
connection = listener.AcceptSocket();
Thread connThread = new ThreadStart(MsgManager));
connThread.Start();
Now I want MsgManager to have access to "connection"
Can someone tell me the accepted practice (if there is one) for getting this connection information to the MsgManager?
Sorry if this is a really stupid question, but I am having a mental block here.
Thanks,
Bob Robey
|
|
|
|
|
If MsgManager is in the same class, you can simply make connection a member variable of that class. If not, the only way I know of is to wrap the Thread within another class (or derive from Thread) and pass connection as a parameter to the constructor of the wrapper.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
I was afraid of that. I just thought someone would have some nifty trick. Thanks for your response.
Regards,
Bob Robey
|
|
|
|
|
I have a little problem
I got a form with a lot off buttons.
i use this code to get the Text of the button i pushed:
string naam,naam2;
naam=sender.ToString();
naam2=naam.Substring(35);
textBox1.Text=naam2;
But the problem is i want to change the color of that button as well.
Could someone tell me how i can determin witch button i pussed with appling just one piece of code to all the buttons?
|
|
|
|
|
Have a common (i.e., the same) event-handler for all the buttons on your form, say ButtonClick. Implement this common event-handler as under, for example:
private void ButtonClick(object sender, System.EventArgs e)
{
if((Button)sender == button1)
{
button1.BackColor = Color.Green;
MessageBox.Show("button1 was clicked", "Form1");
}
else if((Button)sender == button2)
{
button2.BackColor = Color.Pink;
MessageBox.Show("button2 was clicked", "Form1");
}
else if((Button)sender == button3)
{
button3.BackColor = Color.Blue;
MessageBox.Show("button3 was clicked", "Form1");
}
else if((Button)sender == button4)
{
button4.BackColor = Color.Yellow;
MessageBox.Show("button4 was clicked", "Form1");
}
}
It works properly and identifies the correct button pressed. You can add your own code in place of the sample code above. If the number of buttons is too large, you can even consider having an ArrayList of the buttons.
|
|
|
|
|
Hello
you don't have to declare 2 string variables here. Try:
textBox1.Text = sender.ToString().Substring(35);
As to get the button, have you tried:
Button myButton = (Button)sender;
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
The sender argument of your Click event handler _is_ the button that was pressed.
So you can easily cast it to Button and then do with it whatever you want:
private void button_Click(object sender, System.EventArgs e)
{
Button b = sender as Button;
if (b != null)
{
foreach (Control c in this.Controls)
{
if (c is Button)
c.BackColor = SystemColors.Control;
}
b.BackColor = Color.Red;
}
}
Regards,
mav
|
|
|
|
|
And no one has suggested it yet... but this might help:
Button btn = (Button) sender;
MessageBox.Show(btn.Text); I hope this helps!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Ok heres a question its roaming my mind.
Whats the difference doing for example.
SqlConnection con= new SqlConnection(connection_string);
con.close();
con.dispoe();
and
con= null;
AFAIK i think this. Close just clsoes the connection and can be opened again, dipose frees the resources so it cant be opened again, must declare again and null makes the GC get it faster. With this object i see it clearly but its the same for others?
DataSet ds= new DataSet();
Lets take about datasets, if i do a ds.dispose() its completely erased? and what about if i do ds=null; whats will do if i return the dataset in a method and later i do a dispose or a null in the finally clausule.
Ty for ur time.
|
|
|
|
|
Not really. SqlConnection's Close and Dispose do the same thing, if you look at the code, Dispose calls Close. null doesn't necessarily make the GC get it faster, in general, the GC is intelligent enough to figure out that that object has no live references. The only place where setting to null is recommended is if that object is contained within a long living object.
So the answer is
1. Close and Dispose do the same thing. It has nothing to do with GC.
2. Setting to null doesn't make the GC get it faster in most cases.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|