|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
ListBox - Limit Selection Rectangle WidthI have a tabbed listbox. Is there anyway to limit the item selection
rectangle (highlight) to the 1st column instead of having it go across the entire listbox? A tabbed listbox? If that's VB.Net then you're
in the wrong group. If it's VB then I've never heard of a tabbed listbox, but you can do what you want in a listbox. See this code sample: www.jsware.net/jsware/vbcode.php5#lbox If you look at the DrawItem sub in the UserControl you'll see that it paints the background and then the text according to selected colors. It also deals with whether an item is selected. The drawing/painting takes place in a defined rectangle (Rect). To achieve what you want you could use the same colors for selection as for non- selection, then when an item is selected, paint a box on the left with your selection color and inset the rect for the text painting. The result would be that a selected item would show as a normal item marked by a colored square on the left side. If you really had to highlight the first character that should be doable, too, but it'd be more involved. You'd have to paint the background, then paint your selection rect on the left-side, then you'd have to call DrawText twice to do first the first letter and then the rest of the item string. There might also be a tricky part in figuring out exactly how wide that first character will be. See the AddScrollHz sub in the same UserControl for a demo of how to measure the text width. Show quoteHide quote > I have a tabbed listbox. Is there anyway to limit the item selection > rectangle (highlight) to the 1st column instead of having it go across the > entire listbox? > > mayayana
Using VB5 / 6. -------------- This is how you make a Tabbed Listbox 'SetUp ListBox Tab Stops ListBoxTabs(0) = 16 '16/4 = 4 characters ListBoxTabs(1) = 32 '32/4 = 8 characters ListBoxTabs(2) = 64 '64/4 = 16 characters lngDummy = SendMessage(objList.hwnd, LB_SETTABSTOPS, UBound(ListBoxTabs) + 1, ListBoxTabs(0)) '4 ----------------- Thanks for the link. Will take a look see. Show quoteHide quote "mayayana" <mayaXXy***@rcXXn.com> wrote in message news:OvpJUvN$JHA.4984@TK2MSFTNGP05.phx.gbl... >A tabbed listbox? If that's VB.Net then you're > in the wrong group. If it's VB then I've never > heard of a tabbed listbox, but you can do what > you want in a listbox. > See this code sample: > www.jsware.net/jsware/vbcode.php5#lbox > > If you look at the DrawItem sub in the > UserControl you'll see that it paints the > background and then the text according > to selected colors. It also deals with whether > an item is selected. The drawing/painting > takes place in a defined rectangle (Rect). > To achieve what you want you could use > the same colors for selection as for non- > selection, then when an item is selected, > paint a box on the left with your selection > color and inset the rect for the text painting. > The result would be that a selected item > would show as a normal item marked by > a colored square on the left side. If you > really had to highlight the first character that > should be doable, too, but it'd be more > involved. You'd have to paint the background, > then paint your selection rect on the left-side, > then you'd have to call DrawText twice to do > first the first letter and then the rest of the > item string. There might also be a tricky part > in figuring out exactly how wide that first > character will be. See the AddScrollHz sub in > the same UserControl for a demo of how to > measure the text width. > >> I have a tabbed listbox. Is there anyway to limit the item selection >> rectangle (highlight) to the 1st column instead of having it go across >> the >> entire listbox? >> >> > > > This is how you make a Tabbed Listbox I've never seen that before. I looked up> > 'SetUp ListBox Tab Stops > ListBoxTabs(0) = 16 '16/4 = 4 characters > ListBoxTabs(1) = 32 '32/4 = 8 characters > ListBoxTabs(2) = 64 '64/4 = 16 characters > > lngDummy = SendMessage(objList.hwnd, LB_SETTABSTOPS, UBound(ListBoxTabs) > + 1, ListBoxTabs(0)) '4 > LB_SETTABSTOPS but I'm not sure that I understand it. Would the result of your code be that once somebody tabs into your listbox their next tab would take them to item 4, then to item 8, then item 16, then out of the listbox to the next control? What's the point of something like that, that would improve over tabbing between controls and using arrow keys in the listbox? Is it to allow quick access to items that are a ways down the list in a listbox that's accessed frequently? "mayayana" <mayaXXy***@rcXXn.com> wrote Where you been? That's a pretty old trick. This guy was using that in VB2:> > This is how you make a Tabbed Listbox > I've never seen that before. http://vbnet.mvps.org/code/listapi/listboxtabs.htm <Shrug> LFS > > I've never seen that before. So you're going to make me guess> > Where you been? That's a pretty old trick. This guy was using that in VB2: > http://vbnet.mvps.org/code/listapi/listboxtabs.htm > > <Shrug> because I'm so stupid? I hope you never decide to become a nurse or social worker. You just don't have the "bedside manner". :) If I read Randy's page correctly it's setting the width of a tab character. So that's a way to simulate columns in a listbox? That seems very clunky and of limited usefulness, but it makes more sense to me than trapping the tab key in the listbox. When I'd first read David's post I thought he was talking about some kind of tabstrip/ listbox combo control. That's why I wondered if he was using .Net. Odd, when one thinks about it, that the word "tab" has been used so ambiguously. There are 3 possible meanings there, all entirely different. And it took me 3 guesses to figure out which tab we were talking about here! "mayayana" <mayaXXy***@rcXXn.com> wrote Guess what? I wasn't addressing any other thing you> > > I've never seen that before. > > > > Where you been? That's a pretty old trick. This guy was using that in > VB2: > > http://vbnet.mvps.org/code/listapi/listboxtabs.htm > > > > <Shrug> > > So you're going to make me guess > because I'm so stupid? posted, other than how common that idea was. > I hope you never decide to become a nurse There is a little too much of that going around already! <g>> If I read Randy's page correctly it's setting Try it and see. There is a big difference between tab width> the width of a tab character. and tab stop. If it set the tab width, lines like: "cat" & vbTab & "mammal" "elephant" & vbTab & "mammal" Would not be in columns becase the first words are different sizes. Using tab stops appropreatly would leave the "mammal" column all line up from item to item.... LFS "David" <dw85745***@earthlink.net> wrote in message Why not use ListView control? It has that feature.news:uJGrOMN$JHA.4984@TK2MSFTNGP05.phx.gbl... >I have a tabbed listbox. Is there anyway to limit the item selection >rectangle (highlight) to the 1st column instead of having it go across the >entire listbox? Hi Nobody:
Was trying to replicate MS IDE Control Property Window. Spy++ indicates they are using a Listbox. If can't resolve RECT area (select highlight) will go with MSFlexgrid or ListView, but for now like to give it a shot. Show quoteHide quote "Nobody" <nob***@nobody.com> wrote in message news:eznydzd$JHA.4692@TK2MSFTNGP02.phx.gbl... > "David" <dw85745***@earthlink.net> wrote in message > news:uJGrOMN$JHA.4984@TK2MSFTNGP05.phx.gbl... >>I have a tabbed listbox. Is there anyway to limit the item selection >>rectangle (highlight) to the 1st column instead of having it go across the >>entire listbox? > > Why not use ListView control? It has that feature. > > David wrote:
> Was trying to replicate MS IDE Control Property Window. Huh! Never noticed that before. Definitely not native. It's probably owner-drawn. > > Spy++ indicates they are using a Listbox. Example: vbAccelerator - Owner Draw Combo and List Boxes Version 2.1 http://www.vbaccelerator.com/home/vb/Code/Controls/Combo_and_List_Boxes/Owner_Draw_Combo_and_List_Box/article.asp Thanks Karl
Looks like might be more trouble than its worth since Flexgrid should be adaptable fairly easily for what I want to do. Consider thread closed David Show quoteHide quote "Karl E. Peterson" <k***@exmvps.org> wrote in message news:uZyWOo0$JHA.1376@TK2MSFTNGP02.phx.gbl... > David wrote: >> Was trying to replicate MS IDE Control Property Window. >> >> Spy++ indicates they are using a Listbox. > > Huh! Never noticed that before. Definitely not native. It's probably > owner-drawn. Example: > > vbAccelerator - Owner Draw Combo and List Boxes Version 2.1 > http://www.vbaccelerator.com/home/vb/Code/Controls/Combo_and_List_Boxes/Owner_Draw_Combo_and_List_Box/article.asp > -- > .NET: It's About Trust! > http://vfred.mvps.org >
Other interesting topics
VB Express and VB files
Removing too many hyphens Printing contents of a picture box Re: ADO: Deleting a table after it is loaded into Recordset Remote-Desktop "client/ server" Is my VB6 app form open? Vista 64 and Visual Studio 6 In-Process and Out-of-Process Exporting a function from VB.net DLL Need help retrieving a udp response after sending a udp command |
|||||||||||||||||||||||