开发者

Toolbar button sizes in windows mobile 6.5.3

开发者 https://www.devze.com 2023-03-19 21:01 出处:网络
We have a VB.net CF2.0 Apllication that up until now has run on windows mobile platforms from 2003 to 6.0 without any major issues. Our current team use HP iPAQ devices running winodws 6.0 and everyth

We have a VB.net CF2.0 Apllication that up until now has run on windows mobile platforms from 2003 to 6.0 without any major issues. Our current team use HP iPAQ devices running winodws 6.0 and everything runs fine. There is a good, 开发者_如何学编程hardware related reson why we use these devices.

We are looking to update the hardware to motorola hardware running windows mobile 6.5.3 and here in lies the problem. There is a toolbar at the bottom of the application window. This toolbar is made up of several image toolbar buttons that are shown and hidden depending on the functionality of the current screen. On devices up to windows 6.0 all is fine but on windows 6.5.3 it all goes wrong. The toolbar images reamin the same size as always but the clickable area of the button suddenly has become much larger than the image pushing some buttons off the right edge of the screen. You can clearly see when you click the button a large white rectangle much larger than the 40x40 image. this rectangle shows that the control is now much larger than it should be. There doesn't see to be any way to resize this easily. This same effect happens when using the windows 6.5 vga emulator.

I've found the same issue reported by some others online but I couldn't find a suitable solution. Surely this should be simple?

the toolbar is a user control that inherits from System.Windows.Forms.ToolBar and implements a couple of our interfaces (they are very simple and won't affect sizing) and the toolbarbuttons are created directly as New System.Windows.Forms.ToolBarButton and added to the toolbar using .Buttons.Add(...). The images are stored in a System.Windows.Forms.ImageList type. Sizing is applied to the images proportionate to the screen resolution.

All of the above works fine until it is run under 6.5.3. Has anyone come up with a suitable solution to this? Preferrably without rewriting the toolbar code.

thanks in anticipation


I solved this by resizing toolbar after creating it.

NativeMethods.SendMessage(toolBar1.Handle, NativeMethods.TB_SETBUTTONSIZE, 0, NativeMethods.MakeLParam(toolBar1.ImageList.ImageSize.Width, toolBar1.ImageList.ImageSize.Height));

   public static class NativeMethods
    {
        public const int TB_GETBUTTONSIZE = 0x43a;
        public const int TB_SETBUTTONSIZE = 0x41f;
        public const int TB_AUTOSIZE = 0x421;
        public const int TB_SETBITMAPSIZE = 0x420;
        public const int TB_SETBUTTONWIDTH = 0x43b;

        public static int MakeLParam(int LoWord, int HiWord)
        {
            return (int)((HiWord << 16) | (LoWord & 0xffff));
        }

        [DllImport("coredll.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);


    }

At some point toolbar is autosized again, so i have to call this method in Form Activated event. I don't think its the best way to solve this, but at least it worked for me.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号