|
I know of no library to do what you want - I chuck keyboards away if they have all the MM and internet key and buy a business keyboard.
Create and app and detect the keydown event on a form to identify the keys and deal with them the way you need to. Doesn't every developer have a test app where snippets are tried
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi!
How do I save CDATA Object in an XML file?
Thanks
|
|
|
|
|
CDATA is a type of node in an XML file, it isn't an object. You might like to rephrase your question.
|
|
|
|
|
HI all,
i'm trying to populate a panel with an array of picture but when i debug the program is so slow to download the picture in the panel.
i have this code snippet :
public partial class ArtLabel : Form
{
private System.Windows.Forms.PictureBox[] imgArray;
public static string ImageToShow;
private int NumOfFiles;
private string[] imgExtension;
public ArtLabel()
{
InitializeComponent();
panel1.VerticalScroll.Visible = true;
panel1.VerticalScroll.Enabled = true;
panel1.VerticalScroll.Value = panel1.VerticalScroll.Maximum;
}
private void ArtLabel_Load(object sender, EventArgs e)
{
GetPicture4(@"D:\\Music\\");
}
private bool ThumbnailCallback()
{
return false;
}
private void ARR(int cNumber, string exc)
{
int Xpos = 8;
int Ypos = 8;
Image img;
Image.GetThumbnailImageAbort myCallback =
new Image.GetThumbnailImageAbort(ThumbnailCallback);
imgArray = new System.Windows.Forms.PictureBox[cNumber];
for (int i = 0; i < cNumber; i++)
{
imgArray[i] = new System.Windows.Forms.PictureBox();
if (Xpos > 432)
{
Xpos = 8;
Ypos = Ypos + 72;
}
imgArray[i].Left = Xpos;
imgArray[i].Top = Ypos;
imgArray[i].Width = 64;
imgArray[i].Height = 64;
imgArray[i].Visible = true;
imgArray[i].SizeMode = PictureBoxSizeMode.StretchImage;
img = Image.FromFile(exc);
imgArray[i].Tag = exc;
imgArray[i].Click += new System.EventHandler(ClickImage);
imgArray[i].Image = img.GetThumbnailImage(64, 64, myCallback, IntPtr.Zero);
panel1.Controls.Add(imgArray[i]);
Application.DoEvents();
Xpos = Xpos + 72;
}
}
private List<string> GetPicture4(string Folder)
{
DirectoryInfo dir = new DirectoryInfo(Folder);
List<string> str = new List<string>();
FileInfo[] files = dir.GetFiles("*.jpg", SearchOption.AllDirectories);
int NumOfFiles = files.Length;
imgExtension = new string[NumOfFiles];
for (int i = 0; i < NumOfFiles; i++)
{
ARR(i, files[i].FullName);
str.Add(files[i].FullName);
}
return str;
}
private void ClickImage(Object sender, System.EventArgs e)
{
ImageToShow = ((System.Windows.Forms.PictureBox)sender).Tag.ToString();
Direcoty_Prova.ViewPicture f = new Direcoty_Prova.ViewPicture();
f.ShowDialog();
}
}
My purpose of this code is to show the small label of Music Cd and after when i click on the small picture appear a new PictureBox with the picture in Real Size ,i can do it but the trouble if i wish store more than 30 picture in the Array of picture i must wait so long before that the form appear ,i don't know why.
Do you have any advice where i wrong in my code?
Thanks.
Nice Regards
|
|
|
|
|
ascotravel wrote: Do you have any advice where i wrong in my code?
yes.
1.
it is better to use Image.FromStream() rather than Image.FromFile() since the latter keeps the file locked. This is however not affecting performance AFAIK.
2.
it is much better to dispose of all objects you don't need any longer provided their class offers a public Dispose() method. Image class does, so don't just abandon img by assigning a new image to it, first do a if(img!null) img.Dispose(); That will reduce your memory consumption, reducing the work of the garbage collector.
3.
the basic idea of thumbnail images is you don't calculate them over and over; e.g. have your program create thumbnail files (with a modified filename), and look for them when loading. That will avoid the file load and the computation. For small images, avoid compressed formats such as JPEG; use BMP or GIF instead.
BTW: although some image formats support a built-in thumbnail, these are not always present. Furthermore the quality of GetThumbnailImage() is rumored to be not good.
|
|
|
|
|
Replace your ARR method with this:
private void ARR(int cNumber, string exc)
{
int Xpos = 8;
int Ypos = 8;
Image img;
Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
imgArray = new System.Windows.Forms.PictureBox[cNumber];
imgArray[cNumber] = new System.Windows.Forms.PictureBox();
if (Xpos > 432)
{
Xpos = 8;
Ypos = Ypos + 72;
}
imgArray[cNumber].Left = Xpos;
imgArray[cNumber].Top = Ypos;
imgArray[cNumber].Width = 64;
imgArray[cNumber].Height = 64;
imgArray[cNumber].Visible = true;
imgArray[cNumber].SizeMode = PictureBoxSizeMode.StretchImage;
img = Image.FromFile(exc);
imgArray[cNumber].Tag = exc;
imgArray[cNumber].Click += new System.EventHandler(ClickImage);
imgArray[cNumber].Image = img.GetThumbnailImage(64, 64, myCallback, IntPtr.Zero);
panel1.Controls.Add(imgArray[cNumber]);
Xpos = Xpos + 72;
}
I've removed the loop, and the Application.DoEvents call. You were effectively creating the same PictureBoxes many times over
|
|
|
|
|
Hi Thanks to reply me so fast,
for Luc i will follow your advice as i'm a novice i need wise advice..Thanks
@Computafreak - Thanks to post the code but not luck .
When i debug the code in this line code :
<pre> imgArray[cNumber] = new System.Windows.Forms.PictureBox();
appear this error:"Index was outside the bounds of the array.".
I'm trying to work out it if i can i will post my solution.
Thanks a lot for your help.
Nice Regards
|
|
|
|
|
Hi,
If you remove the for loop from the ARR method you have to remove imgArray = new System.Windows.Forms.PictureBox[cNumber]; there as well, and allocate the array at the caller.
|
|
|
|
|
Hi Luc,
sorry i'm shame for my poor knowledge but i removed the loop For and i followed your advices but i receive always the same error .
What i do of wrong???
EDIT : if i remove <code>imgArray = new System.Windows.Forms.PictureBox[cNumber]; and after i debug in this code line
imgArray[cNumber] = new System.Windows.Forms.PictureBox();
i receive this error "Object reference not set to an instance of an object."
modified on Saturday, April 11, 2009 2:22 PM
|
|
|
|
|
Whoops. I missed that one. Follow the instructions at this link
|
|
|
|
|
Hi,
you need a imgArray = new System.Windows.Forms.PictureBox[NumOfFiles]; inside GetPicture4() and none of it inside ARR().
And I strongly suggest you buy a tutorial book on C# and study it. It is the only efficient way to make real progress.
|
|
|
|
|
I tried this code snippet:
private List<string> GetPicture4(string Folder)
{
imgArray = new System.Windows.Forms.PictureBox[NumOfFiles];
DirectoryInfo dir = new DirectoryInfo(Folder);
List<string> str = new List<string>();
FileInfo[] files = dir.GetFiles("*.jpg", SearchOption.AllDirectories);
NumOfFiles = files.Count();
imgExtension = new string[NumOfFiles];
for (int i = 0; i < NumOfFiles; i++)
{
ARR(i, files[i].FullName);
str.Add(files[i].FullName);
}
return str;
}
and after i remode this line
imgArray = new System.Windows.Forms.PictureBox[NumOfFiles];
from the Arr Method but i receive always this error "Index was outside the bounds of the array."
Really sorry maybe i misundertood your advice if yes please be patient i try my best.
Thanks a lot
P.S. i will buy a book as soon as possible,i need improve my English too
|
|
|
|
|
ascotravel wrote: imgArray = new System.Windows.Forms.PictureBox[NumOfFiles];
What do you think is the value of NumOfFiles at this point?
|
|
|
|
|
Okay Luc ,
I work out it after read an article about array ,i removed the method ARR() and i organize the code in the GetPicture4() creating the right loop and removing the messy code wrote down in past.
Thanks for your patience and sorry for my stupidity
Have a good work.
Nice Regards
|
|
|
|
|
How can I create Objects and make them resize them selves according to the Form.
Objects like text Boxes Buttons and more.
Is this is a property?
Thanks for your help
|
|
|
|
|
Look into the Anchor and Dock properties
|
|
|
|
|
Can anyone tell me why do we create DLL files for our project? What is the use of it?
|
|
|
|
|
Because sometimes they may contain support functions. Since they would just contain those particular functions, they're unlikely to contain an entry point, and this would mean that a DLL would be your only option AFAIK
|
|
|
|
|
I need to start with Crystal report Programaticlly, Can anyone help me?
|
|
|
|
|
|
Hello! I want to load a 3,8 MB big file with about 650 000 lines of text (a level file) and write all text to a textbox. But the program crashes when I try to do that! What should I do?
string filetext = String.Empty;
StreamReader tr = new StreamReader(openFileDialog1.FileName);
filetext = tr.ReadToEnd();
tr.Close();
filetext = filetext.Replace("\0", Environment.NewLine);
StringReader sr = new StringReader(filetext);
int counter = 0;
string line = "";
StringBuilder sb = new StringBuilder();
while ((line = sr.ReadLine()) != null)
{
if (line.Length > 0)
{
counter++;
sb.Append(line);
sb.Append(Environment.NewLine);
}
}
richTextBox1.Text = sb.ToString();
|
|
|
|
|
Your program doesn't crash. You simply haven't told it to update the UI thread. Also, you're dumping the text to the RichTextBox all at once. Put that method in a separate Thread, with IsBackground set to true. Also, why are you going through line by line? You've got the file contents, replaced the nulls (which you don't actually need to do - StreamReader stops on a null character), why do you need to append it, line by line, to a StringBuilder?
What you could do is this:
- New thread
- New StreamReader
- Call the SuspendLayout method of the RichTextBox
- Read line by line. Append each line to the RichTextBox
- Call the ResumeLayout method of the RichTextBox
- Close and dispose the StreamReader
|
|
|
|
|
Yes, but the file contains lots of nulls here and there and I want to remove them and display the file's whole text without nulls. And I think it should go faster if I use the string builder.
I have no idea how to do with Threads, can you post a example, please?
The new code:
string filetext = String.Empty;
string line = String.Empty;
StreamReader tr = new StreamReader(openFileDialog1.FileName);
richTextBox1.SuspendLayout();
while ((line = tr.ReadLine()) != null)
{
if (line.Length > 0)
{
line = line.Replace("\0", Environment.NewLine);
richTextBox1.AppendText(line);
richTextBox1.AppendText(Environment.NewLine);
}
}
richTextBox1.ResumeLayout();
tr.Close();
tr.Dispose();
|
|
|
|
|
You cannot display the whole file text without nulls if you read it through a StreamReader. The instant that a StreamReader comes across a null character, it stops reading. It assumes that the file has ended. If you wanted something a little more complex, then you'd have to implement your own
Your original code would not go faster with a StringBuilder, because you've already got everything in a String. Instantiating a StringBuilder would have only slowed it down in this situation, because you had to get the full string, then read it line by line (creating more Strings) into a StringBuilder, thereupon to convert the StringBuilder into the original String to set the RichTextBox's Text property
A Thread is relatively simple to do. It's set up like this
System.Threading.Thread th = new System.Threading.Thread(new Action(() =>
{
})) { IsBackground = true };
th.Start();
IsBackground makes it terminate with your application. You'll also have to use Invoke in order to make thread-safe UI calls. Look into the Action<T> and Func<T> for information about that
|
|
|
|
|
You can't just move Control operations to another thread, that will only result in lots of illegal cross-thread exceptions and/or a hanging GUI.
If your text is line oriented, i.e. you don't want any word wrapping, then a ListBox would be much better at showing the text. It does not need concatenated text lines, it accepts each line as a separate item, and therefore it does not slow down quadratically with the text size.
All it takes is myListBox.Items.Add(line);
|
|
|
|