CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C++ Builder >  基础类

怪怪怪!不信你试试!

楼主wunglee(寂寞让我如此努力)2001-01-01 20:39:00 在 C++ Builder / 基础类 提问

        试试这个原代码,同样的代码,用button和菜单发出命令居然实现不同,而且,程序都无法实现预期功能:如改变选中的字体样式等,为什么?请解释。  
  #include   <vcl.h>  
  #pragma   hdrstop  
   
  #include   "Unit1.h"  
  //---------------------------------------------------------------------------  
  #pragma   package(smart_init)  
  #pragma   resource   "*.dfm"  
  TForm1   *Form1;  
  //---------------------------------------------------------------------------  
  __fastcall   TForm1::TForm1(TComponent*   Owner)  
                  :   TForm(Owner)  
  {  
  }  
  //---------------------------------------------------------------------------  
   
  void   __fastcall   TForm1::BitBtn1Click(TObject   *Sender)  
  {  
      if(FontDialog1->Execute()==True)  
      {  
        RichEdit1->SelAttributes->Style=FontDialog1->Font->Style;  
        RichEdit1->SelAttributes->Size=FontDialog1->Font->Size;  
        RichEdit1->SelAttributes->Name=FontDialog1->Font->Name;  
        RichEdit1->SelAttributes->Color=FontDialog1->Font->Color;  
      }  
  }  
  //---------------------------------------------------------------------------  
   
  void   __fastcall   TForm1::fontset1Click(TObject   *Sender)  
  {  
      if(FontDialog1->Execute()==True)  
      {  
        RichEdit1->SelAttributes->Style=FontDialog1->Font->Style;  
        RichEdit1->SelAttributes->Size=FontDialog1->Font->Size;  
        RichEdit1->SelAttributes->Name=FontDialog1->Font->Name;  
        RichEdit1->SelAttributes->Color=FontDialog1->Font->Color;  
      }  
  }  
  //--------------------------------------------------------------------------- 问题点数:50、回复次数:10Top

1 楼Dinkar(死不了)回复于 2001-01-01 20:56:00 得分 0

简单的把代码改一下在试看看啊  
   
  void   __fastcall   TForm1::fontset1Click(TObject   *Sender)  
  {  
      BitBtn1Click(this);  
  }  
  Top

2 楼Winsky(bcb_user@sina.com)回复于 2001-01-02 08:38:00 得分 0

你的输入焦点跑了。Top

3 楼Wingsun(孙春阳)回复于 2001-01-02 11:40:00 得分 0

对,就是你的输入焦点跑了。你要改一下你的RichiEdit的属性设置了。Top

4 楼wunglee(寂寞让我如此努力)回复于 2001-01-02 13:27:00 得分 0

怎么改?具体点,另外,为什么字体样式设置不起作用?  
  附上头文件!  
   
  //---------------------------------------------------------------------------  
   
  #ifndef   Unit1H  
  #define   Unit1H  
  //---------------------------------------------------------------------------  
  #include   <Classes.hpp>  
  #include   <Controls.hpp>  
  #include   <StdCtrls.hpp>  
  #include   <Forms.hpp>  
  #include   <Buttons.hpp>  
  #include   <ComCtrls.hpp>  
  #include   <Dialogs.hpp>  
  #include   <Menus.hpp>  
  //---------------------------------------------------------------------------  
  class   TForm1   :   public   TForm  
  {  
  __published: //   IDE-managed   Components  
                  TRichEdit   *RichEdit1;  
                  TBitBtn   *BitBtn1;  
                  TFontDialog   *FontDialog1;  
                  TMainMenu   *MainMenu1;  
                  TMenuItem   *fontset1;  
                  void   __fastcall   BitBtn1Click(TObject   *Sender);  
                  void   __fastcall   fontset1Click(TObject   *Sender);  
  private: //   User   declarations  
  public: //   User   declarations  
                  __fastcall   TForm1(TComponent*   Owner);  
  };  
  //---------------------------------------------------------------------------  
  extern   PACKAGE   TForm1   *Form1;  
  //---------------------------------------------------------------------------  
  #endif  
   
   
  去掉与问题无关的内容后源文件为:  
   
   
  //---------------------------------------------------------------------------  
   
  #include   <vcl.h>  
  #pragma   hdrstop  
   
  #include   "Unit1.h"  
  //---------------------------------------------------------------------------  
  #pragma   package(smart_init)  
  #pragma   resource   "*.dfm"  
  TForm1   *Form1;  
  //---------------------------------------------------------------------------  
  __fastcall   TForm1::TForm1(TComponent*   Owner)  
                  :   TForm(Owner)  
  {  
  }  
  //---------------------------------------------------------------------------  
   
  void   __fastcall   TForm1::BitBtn1Click(TObject   *Sender)  
  {  
      if(FontDialog1->Execute()==True)  
      {  
        RichEdit1->SelAttributes->Style=FontDialog1->Font->Style;  
        RichEdit1->SelAttributes->Name=FontDialog1->Font->Name;  
      }  
  }  
  //---------------------------------------------------------------------------  
   
  void   __fastcall   TForm1::fontset1Click(TObject   *Sender)  
  {  
      if(FontDialog1->Execute()==True)  
      {  
        RichEdit1->SelAttributes->Style=FontDialog1->Font->Style;  
        RichEdit1->SelAttributes->Name=FontDialog1->Font->Name;  
      }  
  }  
  //---------------------------------------------------------------------------Top

5 楼babysloth(小懒虫虫)回复于 2001-01-02 17:03:00 得分 0

我不信,也试过了,没问题啊,能把把您的源程序发给我吗?Top

6 楼wunglee(寂寞让我如此努力)回复于 2001-01-09 11:58:00 得分 0

程序早已发给你了,怎么啦?没有回音?Top

7 楼babysloth(小懒虫虫)回复于 2001-01-09 17:33:00 得分 0

信箱出问题了,抱歉,收不到信.发到sloth@myrice.com吧,谢谢.Top

8 楼Darkblack(bloodmud)回复于 2001-01-09 23:19:00 得分 50

Font->Style的设置是有这个问题,如果出现这种情况,用一个中间变量即可     if(FontDialog1-FontDialog1->Execute()==True)  
  {  
      TFontStyles   style;    
      style   =   FontDialog1->Font->Style;  
      RichEdit1->SelAttributes->Style   =   style;  
      RichEdit1->SelAttributes->Name     =   FontDialog1->Font->Name;  
  }  
   
  Top

9 楼wunglee(寂寞让我如此努力)回复于 2001-01-10 08:54:00 得分 0

我也用其他方式解决了这个问题:  
          if(FontDialog1->Execute()==True)  
            RichEdit1->SelAttributes->Assign(FontDialog1->Font);  
  可是,我认为重要的不是在于寻求一个绕过问题的解决方案,而是知道原理,将来才可以借鉴于其他的方面,对吗?  
            哪位高手能说出个原由?一定加分!!!Top

10 楼nicolas(nicolas)回复于 2001-01-10 10:17:00 得分 0

你用不着按钮与菜单写两个事件,其实在你的菜单的OnClick事件中选择BitBtn1Click事件就可以  
  了只是你先要写BitBtn1Click事件.Top

相关问题

  • 怪怪怪怪怪怪
  • 这样的问题你遇到过吗?怪怪怪!!!!!!
  • 不信你就试试。。。。。
  • 怪!怪!怪!
  • 怪~~~怪~~~怪~~~
  • 怪;;怪;;; 怪
  • 怪?怪!怪。
  • 怪!怪!怪!
  • 怪!怪!怪!
  • 怪!怪!!怪!!!

关键词

  • 代码
  • fontdialog
  • selattributes
  • richedit
  • tform
  • fastcall
  • bitbtn
  • fontset
  • tobject
  • font

得分解答快速导航

  • 帖主:wunglee
  • Darkblack

相关链接

  • CSDN Blog
  • 技术文档
  • 代码下载
  • 第二书店
  • 读书频道

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo