怎样在Combobox1加上所有系统打印机,并且使当前combobox1.itemindex为系统默认打印机?

解决方案 »

  1.   

    combobox1.items.assign(printer.printers)这个是加所有的打印机,使当前combobox1.itemindex为系统默认打印机怎么搞?
      

  2.   


    procedure TForm1.Button3Click(Sender: TObject);
    var
      i: integer;
    begin
      for i:=0 to printer.Printers.Count-1 do
      begin
        combobox1.Items.Add(printer.Printers.Strings[i]);
      end;
      combobox1.ItemIndex:= printer.PrinterIndex;
    end;
      

  3.   

    有时候这个printer.PrinterIndex不是显示默认打印机?
      

  4.   

    看看delphi帮助
    Specifies which printer listed in the Printers property is the currently selected printer.Delphi syntax:property PrinterIndex: Integer;
      

  5.   

    如果程序不关闭,我手动去改变系统默认打印机,printer.PrinterIndex就不会变?只有在程序关了,重新开才显示默认的。
      

  6.   

    把按钮事件改成子程序执行一遍
    procedure TForm1.xxx ;
    var
      i: integer;
    begin
      combobox1.clear;
      for i:=0 to printer.Printers.Count-1 do
      begin
        combobox1.Items.Add(printer.Printers.Strings[i]);
      end;
      combobox1.ItemIndex:= printer.PrinterIndex;
    end;
      

  7.   

    解决了procedure TForm1.Button3Click(Sender: TObject);
    var
      i: integer;
      printer: Tprinter;
    begin
      combobox1.Clear;
      printer:=Tprinter.Create;
      for i:=0 to printer.Printers.Count-1 do
      begin
        combobox1.Items.Add(printer.Printers.Strings[i]);
      end;
      combobox1.ItemIndex:= printer.PrinterIndex;
      printer.Free;
    end;