線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1977
推到 Plurk!
推到 Facebook!

關於ListBox

答題得分者是:axsoft
sb055665
一般會員


發表:24
回覆:25
積分:14
註冊:2006-07-12

發送簡訊給我
#1 引用回覆 回覆 發表時間:2006-07-20 13:26:31 IP:211.20.xxx.xxx 未訂閱
請問各位大大,我有一個ListBox,我利用ListBox1Click來判斷,當我所選擇的Item是什麼,就執行什麼,
現在有個問題是,我想利用語音來取代滑鼠點選的方式,
請問有什麼函數可以來做呢?(已經接收到語音下的command了)
現在只要比對,然後執行ListBox1Click就可以了
所以想請問要如何不用滑鼠點的情況下,來做到這樣的動作…
sb055665
一般會員


發表:24
回覆:25
積分:14
註冊:2006-07-12

發送簡訊給我
#2 引用回覆 回覆 發表時間:2006-07-20 13:30:31 IP:211.20.xxx.xxx 未訂閱
功能解釋為
當我輸入"中興路"-->listbox1會自動找到"中興路"
axsoft
版主


發表:681
回覆:1056
積分:969
註冊:2002-03-13

發送簡訊給我
#3 引用回覆 回覆 發表時間:2006-07-20 19:37:34 IP:61.219.xxx.xxx 未訂閱

AutoComplete


資料來源: http://www.dallastech.com/Index.html

Internet Explorer and other Microsoft products feature ComboBoxes that allow the user to type in partial strings and the control automatically completes those strings that match the contents of the drop down list. This is not really a new feature, just a new way to use the existing ComboBox.

This example will demonstrate how to perform autocompletion of strings using Borland C Builder. The techniques employed here apply equally to MFC applications written in Microsoft VisualC .

Create a new project (File|New|Application). Place a checkbox on the default form. You should have something that looks like this:

MainForm.png

Load the strings into the ComboBox drop down list. You can do this at design time from within the IDE or at runtime. This example will utilize runtime loading. Place the following code in the main form constructor. Feel free to change the strings as you like:

    ComboBox->Items->Clear();
    ComboBox->Items->Add("__int64");
    ComboBox->Items->Add("bool");
    ComboBox->Items->Add("char");
    ComboBox->Items->Add("double");
    ComboBox->Items->Add("float");
    ComboBox->Items->Add("int");
    ComboBox->Items->Add("long");
    ComboBox->Items->Add("short");
    ComboBox->Items->Add("wchar_t");

Add the following code to the ComboBox OnKeyDown event. The purpose here is to remember the index into the string array for the currently selected item in the drop down list. The Tag property of the ComboBox is a convenient place to store the index. Tag is defined to be an int, as is the index into the string array.

    // Store the last key the user pressed in the "Tag" property of the
    // TComboBox instance
    TComboBox *CB = dynamic_cast(Sender);
    if (CB != NULL)
        CB->Tag = reinterpret_cast(Key);

Now add the following code to the ComboBox OnChange event processor. This event will fire every time the ComboBox contents is changed - on every key stroke. Note that it takes into account the possibility that the user might type a backspace (0x08) or a delete key. The call to Perform invokes the ComboBox FindString function. This is preferable to using the VCL string array search function. It's a bit faster.

    TComboBox *CB = dynamic_cast(Sender);
    if (CB != NULL)
    {
        // Simply exit if the user pressed the backspace or delete key
        int LastKey = CB->Tag;
        CB->Tag = 0;
        if ((LastKey == 0x08) || (LastKey == VK_DELETE))
            return;            // See if the text in the combo box window already exists in the
        // dropdown list
        int OldPos = CB->SelStart;
        int ix = CB->Perform(CB_FINDSTRING,
                             -1,
                             reinterpret_cast(CB->Text.c_str()));
        if (ix != CB_ERR)
        {
            CB->OnChange = NULL;
            CB->ItemIndex = ix;
            CB->SelStart = OldPos;
            CB->SelLength = CB->GetTextLen() - CB->SelStart;
            CB->OnChange = ComboBoxChange;
        }
    }

Compile the application and check out the results. With version 6 of C Builder, this functionality is integrated with the TCustomComboBox class and its descendents. So there is really no need to implement the code in this example. Simply set the AutoComplete property to true. However, if you are using an older version or Microsoft Visual C , you will have to do it the hard way.

AutoCompleteForm.png

系統時間:2024-04-28 4:36:12
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!