|
Hi,
your code will rescale the original images over and over, every time DrawItem is called.
This is an expensive operation, both for CPU cycles and memory. I suggest you calculate the
images you need just once, at the right size, and keep those available in each item of your ListBox.
That way, your ListBox will scroll much faster, and your memory footprint will be lower.
BTW: not sure how you observe your memory footprint, it not coming down is not necessarily bad.
BTW2: the Image (and hence also the Bitmap) class offers a Dispose() method, you should call it
explicitly when you are done with the Image (Bitmap) for better performance too. Think of it
as closing a file.
|
|
|
|
|
Hi
please help me abuot pdf expire?
for example we want expire the pdf file (TTL=10 days)
thanks
|
|
|
|
|
What are you trying to do ? You can't expire a PDF file, AFAIK.
|
|
|
|
|
Do I Allocate An Expire Date For a PDF File? (SIMILAR Trial Program) How?
Thanks
|
|
|
|
|
I don't think that a PDF file has any property like expiration date.
If it has, you will probably have better luck looking for it in a different forum, as it has nothing at all to do with C# programming...
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi all
I use an error provider in my win form in order to validate some text
boxes value.
My problem is this:if the user input something wrong then the error
provider shows him a
notification,It is logical,but when user correct the value the error
notification is still visible to him
and the user think that he made a mistake again.The same problem is
happened in DatagridView.
what should I do to prevent this?(the error provider disappeared when
user correct his value when he entered)
the following code is a piece of my code which I use:
private void txtName_Validating(object sender,
System.ComponentModel.CancelEventArgs e)
{
if (!IsNameValid())
{
e.Cancel = true;
}
}
private bool IsNameValid()
{
txtName.Text = txtName.Text.Trim();
if (txtName.Text == string.Empty)
{
erp1.SetError(txtName, "Name must not be blank.");
return false;
}
else
{
erp1.SetError(txtName, "");
return true;
}
}
---------------------DataGridView-----------------
void DataGridView1CellValidating(object sender,
DataGridViewCellValidatingEventArgs e)
{
if (dataGridView1.Columns[e.ColumnIndex].HeaderText=="Input")
{
char[] chArray=e.FormattedValue.ToString().ToCharArray();
bool flag=false;
foreach(char ch in chArray){
if(!Char.IsDigit(ch)){
flag=true;
e.Cancel=true;
break;
}
if(flag==true){
dataGridView1.Rows[e.RowIndex].ErrorText = "Invalid Product
Image";
dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText =
"The file name must end with '.gif'.";
}
else
{
dataGridView1.Rows[e.RowIndex].ErrorText = "";
dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText
="";
}
}
}
}
|
|
|
|
|
At the beginning of the validation function reset the error for the control by doing the following
erp1.SetError(txtName, ""); // an empty string hides the error provider.
private bool IsNameValid()
{
erp1.SetError(txtName, "");
txtName.Text = txtName.Text.Trim();
if (txtName.Text == string.Empty)
{
erp1.SetError(txtName, "Name must not be blank.");
return false;
}
else
{
erp1.SetError(txtName, "");
return true;
}
}
|
|
|
|
|
Hi,
How can i simplify a path for filexpto.txt?
c:\folder1\folder13\folder137\folder1376\filexpto.txt
..\\folder1376\\filexpto.txt ????
.\folder1376\filexpto.txt ????
how do you do it?
|
|
|
|
|
This won't truncate the path the way you are asking, but it will compact it. You need to call the PathCompactPathEx from shlwapi.dll.
[DllImport( "shlwapi.dll" )]
static extern bool PathCompactPathEx([Out] StringBuilder pszOut, string szPath, int cchMax, int dwFlags);
static string CompactPath(string path, int length)
{
StringBuilder sb = new StringBuilder();
PathCompactPathEx(sb, path, length, 0);
return sb.ToString();
}
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
You can also check out this article[^].
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Hi,
Does anybody knows how to put a form inside a form in a design way?
Like you can drag/move the inside form to any position.
Imagine you have two forms, the diference is that one is inside the other.
(I not talking about transfer data between forms, i know how to use usercontrols too)
It´s design issue, it´s not really importante to me, but anyone knows thanks!!!
|
|
|
|
|
Hi,
I know that you can add a Form to another Control (e.g. a Form) by setting its TopLevel
property false; I have no idea if that is possible in Visual Designer itself tho.
Not sure how useful it would be either, if it has to be part of a Form right from the start,
why make it a Form first?
|
|
|
|
|
It´s not useful, i don´t need it!
I only wanted to know how is done. I saw it in some applications and it looks nice!
|
|
|
|
|
I wish to do something along the lines of:
MyObject theObject = new MyObject();
DumpObject(theObject);
...
elsewhere...
public void DumpObject(Object obj)
{
string name = GetName(obj); // <<--- This is the part I'm missing
System.Console.WriteLine("The name of the object is " + name);
// this will print out:
// "The name of the object is theObject"
}
I thought I could use reflection to get the name of the object but I'm not having any luck. I know this must be possible, but I'm stumped.
TIA,
Jeff
|
|
|
|
|
how you can get object name if it doesn't have Name property , or you just want to know its type?
dhaim
program is hobby that make some money as side effect
|
|
|
|
|
No, I can't assume that the object has a Name property, and I don't want to know the type (which I'd just do Type t = myObject.GetType()).
I'm developing a (generic) debugging routine, so if I passed a variable named someObject:
MyMethod(someObject);
...at runtime I want to get "someObject". I'd like to, and I'm sure there is a way, but I'm not seeing how to do it.
Thanks though,
Jeff
|
|
|
|
|
Hi Jeff,
1.
you are confusing objects with references. An object can have a name (say you provide a Name property),
a reference only refers to the object.
Also there could be many references to the same object.
How about
MyObject theObject=new MyObject("Paul");
MyObject anotherReference=theObject;
DumpObject(anotherReference);
Now which name would you want to get?
The only one you will be able to get is "Paul" provided it got stored somewhere *inside* the object.
2.
It is however possible to get the name of the reference itself, using reflection.
But then you have to pass the reference itself, hence something like:
MyObject theObject=new MyObject("Paul");
MyObject anotherReference=theObject;
DumpObject(ref anotherReference);
Now DumpObject gets hold of anotherReference itself, and through reflection should be able
to get at its name. Haven't done this though, when names are important I store them inside the
object.
|
|
|
|
|
Luc Pattyn wrote: MyObject theObject=new MyObject("Paul");
MyObject anotherReference=theObject;
DumpObject(anotherReference);
Now which name would you want to get?
The only one you will be able to get is "Paul" provided it got stored somewhere *inside* the object.
With the above code, I'd want to get the string "anotherReference" inside of DumpObject(). If the code was DumpObject(theObject), I'd want to get the string "theObject" inside of DumpObject().
Luc Pattyn wrote: It is however possible to get the name of the reference itself, using reflection.
Luc Pattyn wrote: and through reflection should be able
to get at its name.
That's the part I'm not able to do.
Thanks though,
Jeff
|
|
|
|
|
No, it's not possible. An instance of an object doesn't have a name, neither has the reference to it.
The variable holding the reference does have a name, but that is not passed along to the method, neither is a reference to the variable. Also, unless the assembly is started with debug information, I don't think that you can even get the name of a local variable.
There might not even be a variable holding the reference. Consider these examples:
Here you have no variable at all:
DumpObject(new MyObject());
Here the variable is just a member of a KeyValuePair structure in a dictionary:
Dictionary<int,MyObject> MyDictionary = new Dictionary<int,MyObject>();
MyDictionary.Add(42, new MyObject());
DumpObject(MyDictionary[42]);
What would you imagine that the name should be; "Value", "42" or "MyDictionary"?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Right.
What was I thinking again?
so only solution is to put a Name inside the object, and forget reference names altogether.
|
|
|
|
|
But then, what's the name of the Name?
|
|
|
|
|
.NET 4.0 is rumored to provide introspection for that very purpose.
|
|
|
|
|
That's cool, but I can't wait that long. For now what I'm going to do is something like:
DumpObject(theObject, "theObject");
Thanks,
Jeff
|
|
|
|
|
OK.
FYI: There used to be a little preprocessor trick to automate that in C and C++ (using some ## magic),
but that is not available in C#...
|
|
|
|
|
Hi, do you want to acess a object from a form in otherform?
|
|
|
|