当前位置: 首页 > 编程语言 > C#

ComboBoxDropdownPositionSharing

时间:2023-04-11 11:43:29 C#

ComboBoxDropdownPosition我有一个最大化的表单,它有一个500px宽度的Combo-Box控件(停靠在右上角)尝试打开组合框后,列表的一半出现在屏幕外。如何在表单中强制显示列表?棘手的问题。我找不到好的解决方案,只有解决方法。添加一个新类并粘贴如下所示的代码。编译。将新控件从工具箱顶部拖放到窗体上。解决方法不是很好。问题是下拉窗口将忽略移动它的尝试,直到下拉动画完成。视觉效果不是很好,你会看到窗口下降,然后跳到左边。我不知道还有另一种方法可以击中它的头,也许其他人也这样做。C#版本:usingSystem;使用系统绘图;使用System.Windows.Forms;使用System.Runtime.InteropServices;publicclassMyComboBox:ComboBox{protectedoverridevoidOnDropDown(EventArgse){//下拉菜单是否在屏幕右侧?Pointpos=this.PointToScreen(this.Location);屏幕scr=Screen.FromPoint(pos);if(scr.WorkingArea.Right{//检索下拉列表的句柄COMBOBOXINFOinfo=newCOMBOBOXINFO();info.cbSize=Marshal.SizeOf(info);SendMessageCb(this.Handle,0x164,IntPtr.Zero,outinfo);//移动下拉窗口RECTrc;GetWindowRect(info.hwndList,outrc);intx=scr.WorkingArea.Right-(rc.Right-rc.Left);SetWindowPos(info.hwndList,IntPtr.Zero,x,rc.Top,0,0,5);}));}base.OnDropDown(e);}//P/Invoke声明privatestructCOMBOBOXINFO{publicInt32cbSize;公共RECTrcItem,rcButton;公共诠释按钮状态;publicIntPtrhwndCombo,hwndEdit,hwndList;}privatestructRECT{公共整数左、上、右、下;}[DllImport("user32.dll",EntryPoint="SendMessageW",CharSet=CharSet.Unicode)]privatestaticexternIntPtrSendMessageCb(IntPtrhWnd,intmsg,IntPtrwp,outCOMBOBOXINFOlp);[DllImport("user32.dll")]privatestaticexternboolSetWindowPos(IntPtrhWnd,IntPtrafter,intx,inty,intcx,intcy,intflags);[DllImport("user32.dll")]privatestaticexternboolGetWindowRect(IntPtrhWnd,outRECTrc);}VB.Net版:以上就是C#学习教程:ComboBox下拉位置分享的全部内容。如果对大家有用,需要详细了解C#学习教程,希望请关注—ImportsSystemImportsSystem.DrawingImportsSystem.Windows.FormsImportsSystem.Runtime.InteropServicesPublicClassMyComboBoxInheritsComboBox'P/Invoke声明PrivateStructureCOMBOBOXINFOPubliccbSizeAsInt32PublicrcItemAsbuttonRECTPublicrcButtonIntegerPublichwndComboAsIntPtrPublichwndEditAsIntPtrPublichwndListAsIntPtrEndStructure私有结构RECTPublicLeftAsIntegerPublicTopAsIntegerPublicRightAsIntegerPublicBottomAsIntegerEndStructure私有共享函数SendMessageCb(hWndAsIntPtr,msgAsInteger,wpAsIntPtr,ByReflpAsCOMBOBOXINFO)AsIntPtrEndFunctionPrivatePindowPos,InthWndafterAsIntPtr,xAs整数,y作为整数,cx作为整数,cy作为整数,标记为整数)作为布尔结束函数私有共享函数GetWindowRect(hWnd作为IntPtr,ByRefrc作为RECT)作为布尔结束函数保护覆盖向下OnDrop(e作为EventArgs)'下拉菜单是否在屏幕右侧?DimposAsPoint=Me.PointToScreen(Me.Location)DimscrAsScreen=Screen.FromPoint(pos)If(scr.WorkingArea.RightCollection不代表位置。如涉及侵权,请点击右侧联系管理员删除,如需转载请注明出处:

最新推荐
猜你喜欢