Click here to Skip to main content
15,906,574 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
Questionadding a panel to a form. Pin
bimbambumbum22-Sep-10 13:53
bimbambumbum22-Sep-10 13:53 
AnswerRe: adding a panel to a form. Pin
bimbambumbum22-Sep-10 14:03
bimbambumbum22-Sep-10 14:03 
AnswerRe: adding a panel to a form. Pin
Luc Pattyn22-Sep-10 14:04
sitebuilderLuc Pattyn22-Sep-10 14:04 
GeneralRe: adding a panel to a form. [modified] Pin
bimbambumbum22-Sep-10 14:42
bimbambumbum22-Sep-10 14:42 
AnswerRe: adding a panel to a form. Pin
Luc Pattyn22-Sep-10 15:28
sitebuilderLuc Pattyn22-Sep-10 15:28 
GeneralRe: adding a panel to a form. Pin
bimbambumbum22-Sep-10 17:04
bimbambumbum22-Sep-10 17:04 
AnswerRe: adding a panel to a form. Pin
Luc Pattyn22-Sep-10 17:13
sitebuilderLuc Pattyn22-Sep-10 17:13 
GeneralRe: adding a panel to a form. Pin
bimbambumbum25-Sep-10 4:46
bimbambumbum25-Sep-10 4:46 
Hi Luc

I'm about to give up on the panel approach and just use the dramimage-method and live with the flickering. Below you can see me panel approach...it does work but it flickers just a much as the drawimage approach.

Do you mind taking a look at my code and tell me what I'm doing wrong? I'm not into the terminology of windows programming so I'd appreciate a no-brainer description on how to do this Smile | :)

My drawing code looks like this:
            g = pe.Graphics;

            int H = myBitmap.Height;
            int W = myBitmap.Width;

            Rectangle rect = new Rectangle(0, 0, W, H);
            myBitmapData = myBitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, myBitmap.PixelFormat);

            // Get the address of the first line.
            IntPtr ptr = myBitmapData.Scan0;

            // Declare an array to hold the bytes of the bitmap.
            int bytes = myBitmapData.Stride * H;
            byte[] rgbValues = new byte[bytes];

            // Copy the RGB values into the array.
            System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);

            // Shift the first N-1 columns one pixel to the right
            for (int ii = 0; ii < H; ii++)
                for (int jj = (ii + 1) * (3 * W) - 1; jj > (ii * W * 3) + 3; jj -= 3)
                {
                    rgbValues[jj] = rgbValues[jj-3];
                    rgbValues[jj-1] = rgbValues[jj-4];
                    rgbValues[jj-2] = rgbValues[jj-5];
                }

            // fill in some random data in the first column
            int offset = W * 3;
            for (int counter = 0; counter < H; counter += 1)
            {
                rgbValues[counter * offset] = (byte)rnd.Next(255);
                rgbValues[counter * offset + 1] = (byte)rnd.Next(255);
                rgbValues[counter * offset + 2] = (byte)rnd.Next(255);
            }

            // Copy the RGB values back to the bitmap
            System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes);

            // Unlock the bits.
            myBitmap.UnlockBits(myBitmapData);
            myPanel.Location = new Point(XREF, YREF);
            myPanel.Width = myBitmap.Width;
            myPanel.Height = myBitmap.Height;
            myPanel.BackgroundImage = myBitmap;
            this.Controls.Add(myPanel);

My panel class (read that double buffering with a panel should be done like this):

   public class DoubleBufferPanel : Panel
        {
            public DoubleBufferPanel()
            {
                // Set the value of the double-buffering style bits to true.
                this.SetStyle(ControlStyles.DoubleBuffer |
                ControlStyles.UserPaint |
                ControlStyles.AllPaintingInWmPaint,
                true);
                this.UpdateStyles();
            }
        }


Hope to hear from you

Thanks
Tom
GeneralRe: adding a panel to a form. Pin
Luc Pattyn25-Sep-10 5:21
sitebuilderLuc Pattyn25-Sep-10 5:21 
GeneralRe: adding a panel to a form. [modified] Pin
bimbambumbum25-Sep-10 5:31
bimbambumbum25-Sep-10 5:31 
GeneralRe: adding a panel to a form. Pin
Luc Pattyn25-Sep-10 6:08
sitebuilderLuc Pattyn25-Sep-10 6:08 
GeneralRe: adding a panel to a form. [modified] Pin
bimbambumbum25-Sep-10 11:20
bimbambumbum25-Sep-10 11:20 
GeneralRe: adding a panel to a form. Pin
Luc Pattyn25-Sep-10 12:02
sitebuilderLuc Pattyn25-Sep-10 12:02 
QuestionsqlDataAdapter doest not refresh the query Pin
akosidandan22-Sep-10 5:20
akosidandan22-Sep-10 5:20 
AnswerRe: sqlDataAdapter doest not refresh the query Pin
Not Active22-Sep-10 7:42
mentorNot Active22-Sep-10 7:42 
GeneralRe: sqlDataAdapter doest not refresh the query Pin
akosidandan22-Sep-10 22:40
akosidandan22-Sep-10 22:40 
GeneralRe: sqlDataAdapter doest not refresh the query Pin
Not Active23-Sep-10 1:08
mentorNot Active23-Sep-10 1:08 
QuestionHow to Show Specific Records in listview Pin
akosidandan22-Sep-10 1:38
akosidandan22-Sep-10 1:38 
AnswerRe: How to Show Specific Records in listview Pin
Luc Pattyn22-Sep-10 2:23
sitebuilderLuc Pattyn22-Sep-10 2:23 
GeneralRe: How to Show Specific Records in listview Pin
akosidandan22-Sep-10 2:29
akosidandan22-Sep-10 2:29 
GeneralRe: How to Show Specific Records in listview Pin
Luc Pattyn22-Sep-10 2:47
sitebuilderLuc Pattyn22-Sep-10 2:47 
QuestionFile recovery Pin
hammerstein0522-Sep-10 0:57
hammerstein0522-Sep-10 0:57 
AnswerRe: File recovery Pin
Pete O'Hanlon22-Sep-10 1:37
mvePete O'Hanlon22-Sep-10 1:37 
GeneralMessage Removed Pin
22-Sep-10 4:23
molesworth22-Sep-10 4:23 
GeneralRe: File recovery Pin
Pete O'Hanlon22-Sep-10 4:35
mvePete O'Hanlon22-Sep-10 4:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.