|
You'll want to use the Control's Invalidate(Rectangle rc) method (see MSDN[^])
panel.Invalidate(new Rectangle(0, 0, 100, 100));
Then when you paint the panel you only paint an image if its bounding rectangle intersects with the clip rectangle
protected override void OnPaint(PaintEventArgs e)<br />
{<br />
Rectange imageRect = new Rectangle(imageX, imageY, imageWidth, imageHeight);<br />
<br />
if (imageRect.IntersectsWith(e.ClipRectangle))<br />
{<br />
e.Graphics.DrawImage(image, imageRect);<br />
}<br />
}
"I think I speak on behalf of everyone here when I say huh?" - Buffy
|
|
|
|
|
I want that control (Label, TextBox) with property Enabled = false don't change it ForeColor to grey.
For example I have a UserControl with TextBox or Label on it. I can change TextBox property BackColor very easy:
private void UserControl1_EnabledChanged(object sender, System.EventArgs e)<br />
{<br />
if(this.Enabled)<br />
{<br />
}<br />
else<br />
{<br />
this.TextBox1.BackColor = System.Drawing.Color.White;<br />
}<br />
}
But I can't change TextBox(Label) property ForeColor!
private void UserControl1_EnabledChanged(object sender, System.EventArgs e)<br />
{<br />
if(this.Enabled)<br />
{<br />
this.BackColor = System.Drawing.Color.White;<br />
}<br />
else<br />
{<br />
this.textBox1.BackColor = System.Drawing.Color.White;<br />
this.textBox1.ForeColor = System.Drawing.Color.Black;<br />
<br />
this.Label1.ForeColor = System.Drawing.Color.Black;<br />
}<br />
}
This code can't do this!
If I make MyLabel by inheritance of Label and overide OnEnabledChanged(...), this will not help too:
protected override void OnEnabledChanged(EventArgs e)<br />
{<br />
}
If I put MyLabel on UserControl1 and then change Enable property of UserControl1 to false, the ForeColor property of MyLabel will not change!
But when I deactivate form with this control and then activate it, text of MyLabel will be grey.
Please, help!
|
|
|
|
|
In my humble opinion it is not wise to change the way disabled controls appear to the user. It can confuse people.
If you look into the Label implementation you will see that the disabled appearance of is hardcoded in. You cannot do anything about how a disabled Label looks.
However, if you really need to change something... create your own label implementation.
Alex Korchemniy
|
|
|
|
|
Some people have problems with monocrome LCD screens, where the text in textBoxes are almost invisible when they have Enabled set to false.
So actually it would be nice to be able to change that color...
Just a point of view.
I'm in the high-fidelity first class traveling set.
And I think I need a Lear jet.
|
|
|
|
|
where i can download the msdn in spanish
|
|
|
|
|
|
Hello everyone,
I have a question on garbage collection that you guys will probably be able to answer in a snap. Here goes...
If I do this...
<br />
public void DoSomethingHere()<br />
{<br />
MyCustomClass mcc = new MyCustomClass();<br />
mcc.PerformFunction();<br />
<br />
mcc = new MyCustomClass();<br />
mcc.PerformAnotherFunction();<br />
}<br />
As you'll see above, mcc has performed a new twice. I'm just curious as to what happens to the memory from the first "new". Will the garbage collector know about it and clean it up later on, or is this considered a memory leak which will just sit in limbo?
Thanks,
~Brad
|
|
|
|
|
The garbage collector will pick it up - anything non-static that nobody has a reference to will be picked up.
|
|
|
|
|
Thank you.
|
|
|
|
|
GC will handle it because the first object will no longer be referenced. However be careful with objects that have resources that need to be released.
This makes a big mess:
Bitmap b = new Bitmap(100, 100);<br />
for(int i = 0 ; i < 1000; i++)<br />
{<br />
b = new Bitmap(100, 100);<br />
}
This is correct:
Bitmap b = new Bitmap(100, 100);<br />
for(int i = 0 ; i < 1000; i++)<br />
{<br />
b.Dispose();<br />
b = new Bitmap(100, 100);<br />
}
Alex Korchemniy
|
|
|
|
|
|
how to fit the height of more than one labels at same time in a main form if the labels textlines increes their height while the form width its changing plz helpme with this issue
|
|
|
|
|
If I understand you correctly... you are trying to achieve flow layout.
If all you have on the form is a few labels it would be better to do custom drawing code. For each string you draw you do MeasureString . Using the SizeF that is returned you can calculate where to draw the next string.
Alex Korchemniy
|
|
|
|
|
hi alex thanks by the form isuue but this one i dont understand so much can u explainme better
the labels are putted on runtime not on desingtime and their dock property are setit to top
|
|
|
|
|
Do away with labels completely. I'm assuming that you have no other controls in the way to worry about. Instead handle the Paint event for the form. Inside the paint event "draw" the strings that you have. For each string you draw you keep a record of the location. You can also add padding if necessary. Also make sure that everything is redrawed when resize occurs.
Off the top of my head and not tested:
Graphics g = e.Graphics;<br />
int currentY = 0;<br />
foreach(string s in myStringArray)<br />
{<br />
SizeF sz = g.MeasureString(s, this.Font, this.Width);<br />
g.DrawString(s, this.Font, Brushes.Black, new Rectangle(0, currentY, (int)sz.Width, (int)sz.Height));<br />
currentY += (int)sz.Height;<br />
currentY += 10;
}
Alex Korchemniy
|
|
|
|
|
How to minimize a main form while the closing event with out dispose or close the form;
|
|
|
|
|
Handle the Closing event. In the event set the Visible to false. To prevent the Form from closing in the CancelEventArgs that you get with the event handler set Cancel to true.
See: MSDN docs[^]
Alex Korchemniy
|
|
|
|
|
U could say something:
private void FrmMain_Closing(object sender, System.ComponentModel.CancelEventArgs e)<br />
{<br />
this.WindowState = FormWindowState.Minimized;<br />
this.Hide();<br />
e.Cancel = true;<br />
}
Regards,
Polis
Can you practice what you teach?
|
|
|
|
|
Hi, I have added an SMTP appender to my application using Log4Net for logging and notification - but how do you change pre-configured value (in App.Config)? Here's appender section in my configuration file:
<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
<to value="xxx@xxx.com" />
<from value="xxx@xxx.com" />
<subject value="xxx" />
<smtpHost value="localhost" />
<bufferSize value="512" />
<lossy value="true" />
<evaluator type="log4net.Core.LevelEvaluator">
<threshold value="WARN"/>
</evaluator>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%newline%date [%thread] %-5level %logger [%ndc] - %message%newline%newline%newline" />
</layout>
</appender>
The closet thing I found is: http://www.ondotnet.com/pub/a/dotnet/2003/06/16/log4net.html?page=3
But, that's adding a new appender altogether, not re-configuring existing appenders. I need to change to/from email address. Thanks in advance.
Norman Fung
|
|
|
|
|
public class MyDataSet : DataSet
{
private string _sample;
public MyDataSet()
{
}
public string Sample
{
get{return _sample;}
set{_sample = value;}
}
}
When Serialize and Deserialize it alway return
DataSet not MyDataSet.
Help me please
Thank You.
|
|
|
|
|
How are you attempting to serialize and deserialize your type? Are you using binary or xml serialization?
Using binary serialization, I had no trouble serializing a class that inherits from DataSet and deserializing it, receiving the same subtype. Since DataSet implements ISerializable, you do have to provide a deserialization constructor to pass through the info and context to the base class.
Example:
<br />
[Serializable]<br />
public class MyDataSet : DataSet<br />
{<br />
private string _sample;<br />
<br />
public MyDataSet(): base() {}<br />
protected MyDataSet (SerializationInfo info, StreamingContext context) : base (info, context) {}<br />
<br />
<br />
public string Sample<br />
{<br />
get {return _sample;}<br />
set {_sample = value;}<br />
}<br />
}
Then I just tested it with some code like:
MyDataSet mds = new MyDataSet();<br />
<br />
mds.Sample = "Some sample text.";<br />
<br />
BinaryFormatter formatter = new BinaryFormatter();<br />
MemoryStream stream = new MemoryStream();<br />
<br />
formatter.Serialize(stream, mds);<br />
<br />
stream.Position = 0;<br />
MyDataSet mds2 = formatter.Deserialize(stream);<br />
<br />
stream.Close();<br />
<br />
Console.WriteLine(mds2.SampleString);
Another handy feature of DataSets, if this doesn't work out for you and you're looking for something simple, is the ExtendedProperties hashtable. One thing to note is that the data added to the collection must be in string form to guarantee that it'll be persisted if and when the DataSet is serialized to XML.
Hope this helps.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Thank you very much, Sir.
I will try it again.
My code don't have
[Serializable]
and
protected MaoDataSet (SerializationInfo info, StreamingContext context) : base (info, context) {}
|
|
|
|
|
Dear, Sir.
I have another problem.
I have a class named MyTable derives from DataTable
I add it to MyDataSet.Tables[]
after Serialization and Deserialization
I get DataTable but cannot get MyTable
Thank again.
|
|
|
|
|
--------------------------------------------------------------------------------
Hi
I have a basic question. I want to copy a table in a db to another db (in the destination the table has to be created first with proper columns). the table name and schema will remain same. (I'm using sql server 2000).
Can you provide sample ado.net code, by which I can achieve that?
Thanks
|
|
|
|
|
This question belongs on the ADO/SQL board. Since I wrote the reply to it before stopping to consider that fact, I'll post it here, but in the future, try to keep the questions on-topic, please.
Assuming your tables are on the same server instance (otherwise you'll have to further qualify the table objects, link servers etc.):
INSERT INTO [new database name].[owner id].[new table name]<br />
SELECT * FROM [old database name].[owner id].[old table name]
Example:
INSERT INTO sampledatabase2.dbo.table1<br />
SELECT * FROM sampledatabase1.dbo.table1
This example uses the '*' wildcard for brevity. You really should list out the columns in your own code.
As for what code you might use, I would suggest using a SqlConnection and a SqlCommand (using the ExecuteNonQuery method of the SqlCommand to execute the above syntax).
As an alternative to creating the schema by hand, and assuming you have appropriate permissions, you could also do something like:
SELECT [old database name].[owner id].[old table name].*<br />
INTO [new database name].[owner id].[new table name]<br />
FROM [old database name].[owner id].[old table name]
Example:
SELECT sampledatabase2.dbo.table1.* <br />
INTO sampledatabase1.dbo.tablefoo<br />
FROM sampledatabase2.dbo.table1
but explicitly creating the schema, or using a script created from the original is safer.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|