Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
for reflecting the changes after re-sizing the window, how to get handle to the window in C# 


actually my problem is when I re-size the window the contents of the files that are displayed in the window in hexadecimal format with 16,32.. like this, should be changed to hexadecimal format with 8,16,24... in this format.
C#
// this is the code for opening a file and display in hexadecimal format
       public void open()
       {
           string chosen_file = "";
           ofd.Title = "Open a file";
           ofd.FileName = "";
           ofd.Filter = "Text Files(*.txt)|*.txt|Rich Text Box(*.rtb)|*.rtb|Word Document(*.doc)|*.doc|HTML Pages(*.htm)|*.html|Cascading Style Sheet(*.css)|*.css|JAVA(*.java)|*.java|video file(*.wmv)|*.wmv|All Files(*.*)|*.*";
           if (ofd.ShowDialog() == DialogResult.OK)
           {
               chosen_file = ofd.FileName;
               // richTextBox2.LoadFile(chosen_file, RichTextBoxStreamType.PlainText);

               var fileInfo = new FileInfo(ofd.FileName);
               fileInfo.Length.ToString();
               //  MessageBox.Show(new FileInfo(ofd.FileName).Length.ToString());
               byte[] buffer = new byte[fileInfo.Length];

               {
                   int length = (int)fileInfo.Length;
                   FileStream fileStream = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read);
                   fileStream.Read(buffer, 0, length);
                   string bb = "";
                   int i = 0;
                   //int numBytesToRead = buffer.Length; ;
                   while (i < buffer.Length)
                   {
                       if ((i % 16) == 0)
                       {
                           bb = bb + "\n";
                           bb = bb + i.ToString("X8");
                           bb = bb + "\t";
                       }
                       else if ((i % 4) == 0)
                       {
                           bb = bb + "\t";
                       }
                       bb = bb + buffer[i].ToString("X2"); // modified on 30june2014
                       // if ((i % 4) == 0)
                       // {
                       //
                       // }
                       i = i + 1;
                   }
                   richTextBox2.Text = bb;
               }




C#
// this is the code for resizing but it has some problems 
//1. how to fetch the data and how to convert the data 

        private void PaintForm_Resize(object sender, System.EventArgs e)
        {
            //Width = 580;
            //Height = 487;
            //string []buffer =new byte[ richTextBox2.Text];
            //byte[] buffer2 = Encoding.Default.GetBytes(richTextBox2.Text);
         
            
            //int scaleX = this.Width / 100;
            //int scaleY = this.Height / 100;
            //paintImage.SetBounds(5 * scaleX, 5 * scaleY, 70 * scaleX, 75 * scaleY);
            //controlPanel.SetBounds(80 * scaleX, 5 * scaleY, 15 * scaleX, 75 * scaleY); 

           
            byte[] buffer = new byte[richTextBox2.Text.Length];
                      
            //  int length = (int)richTextBox2.TextLength;
            //  int length = (int)buffer.Length;


            //filestream filestream = new filestream(ofd.filename, filemode.open, fileaccess.read);
            //filestream.read(buffer, 0, length);

            //From byte array to string

            string bb ="";
            int i = 0;
            //int numBytesToRead = buffer.Length; 
            while (i < buffer.Length)
            {
                if ((i % 8) == 0)
                {
                    bb = bb + "\n";
                    bb = bb + i.ToString("X8");
                    bb = bb + "\t";
                }
                else if ((i % 4) == 0)
                {
                    bb = bb + "\t";
                }
                bb = bb + buffer[i].ToString("X2");
                // bb = bb + richTextBox2.Text[i].ToString("X2");

                i = i + 1;
            }

            richTextBox2.Text = bb;

          
        }
Posted
Updated 11-Sep-14 1:26am
v6

1 solution

Well, you could use the Handle[^] property...
 
Share this answer
 
Comments
OriginalRocky 9-Sep-14 2:13am    
@OriginalGriff, actually my problem is when I re-size the window the contents of the files that are displayed in the window in hexadecimal format with 16,32.. like this, should be changed to hexadecimal format with 8,16,24... in this format. Please help me SIR..
OriginalGriff 9-Sep-14 3:04am    
No, you are going to have to explain that in rather better detail.
What do files have to do with window handles?

Remember, I can't see your screen, access your HDD, or read your mind! :laugh:
OriginalRocky 9-Sep-14 3:18am    
I know but the thing is to get handle of the window to resize and reflect the changes in the window.., I think that is done trough the api.

OriginalGriff 9-Sep-14 3:32am    
Um...why?

There is the Control.Resize event...and Form is derived from Control...so why would you need the window handle?
OriginalRocky 9-Sep-14 6:10am    
because, without using window handle I can not reflect the changes after resizing the window.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900