比如我下拉选项是有:
‘1     名称’
‘2     姓别’
‘3     大小’
我想当选中,其中任何一项时,combobox1.text是选中项前面的那个数字而已,而不是全部。
我本想在oncloseup的事件中这样处理:
combobox1.text:=copy(combobox1.text,1,4);
但发觉得是办不到的。
请问我应该怎样修改这个事件本身。它对应的消息是哪一个?

解决方案 »

  1.   

    在ComboBox的OnChage事件中截取ComboBox.Items.Strings[ComboBox.ItemIndex]的前1个字符就行了。
      

  2.   

    我猜你是要在ComboBox中选中一项,然后获取“1”“2”之类的数值吧?procedure TForm1.ComboBox1Change(Sender: TObject);
    var
        strText: String;
    begin
        strText := ComboBox1.Items.Strings[ComboBox1.ItemIndex];
        Edit1.Text := Copy(strText, 1, 1);
    end;这样,Edit1.Text中就是1,2,3之类的数值。具体如何应用,你自己考虑。
      

  3.   

    我是想这样。
    procedure TForm1.ComboBox1Change(Sender: TObject);
    begin
    combobox1.Text:=copy(combobox1.Items.Strings[combobox1.itemindex],1,3);
    end;
    但是combobox1.Text没效果。
      

  4.   

    晕。原来是要这样的效果。wait
      

  5.   

    procedure TForm1.FormCreate(Sender: TObject);
    begin
        ComboBox1.Items.Add('1  姓名');
        ComboBox1.Items.Add('2  性别');
        ComboBox1.Items.Add('3  年龄');
        ComboBox1.Style := csOwnerDrawFixed;
        ComboBox1.ItemHeight := 18;
    end;
    procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    begin
        ComboBox1.Canvas.FillRect(Rect);
        ComboBox1.Canvas.TextOut(Rect.Left + 1, Rect.Top + 1,
                Copy(ComboBox1.Items.Strings[Index], 1, 1));
    end;
      

  6.   

    //trytype
      TForm1 = class(TForm)
        ComboBox1: TComboBox;
        procedure ComboBox1Select(Sender: TObject);
      private
        { Private declarations }
        procedure WMUSER10(var Msg: TMessage); message WM_USER + 10;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.ComboBox1Select(Sender: TObject);
    begin
      PostMessage(Handle, WM_USER + 10, Integer(Sender), 0);
    end;procedure TForm1.WMUSER10(var Msg: TMessage);
    begin
      TComboBox(Msg.WParam).Text := Copy(TComboBox(Msg.WParam).Text, 1, 4);
    end;
      

  7.   

    谢谢上面那位高人..但小弟看不太懂..你能解一下吗?
    1.为什么要在COMBOBOX1SELECT 下发送消息?
    2.TComboBox(Msg.WParam).Text 里面Msg.WParam的是什么意思?谢谢
      

  8.   

    ComboBox.OnSelect就是用户选择一个条目时触发的事件PostMessage();就是发送消息但不等待执行 // 目的跳出 ComboBox1Select 的堆栈调用
    Msg.WParam对应的就是PostMessage(/, /, Integer(Sender), /);
    实际上就是这样:
    procedure TForm1.ComboBox1Select(Sender: TObject);
    begin
      PostMessage(Handle, WM_USER + 10, 0, 0);
    end;procedure TForm1.WMUSER10(var Msg: TMessage);
    begin
      ComboBox1.Text := Copy(ComboBox1.Text, 1, 4);
    end;
    前面的代码适合更具有通用性