#t#本人很喜欢Visual Studio,在工作中也很喜欢总结关于创建Visual Studio辅助控件的经验教训,下面就这个问题来详细说说吧。Visual Studio 2010为了支持现代软件对丰厚的界面交互方式的要求,于是就提供了很多其他的Visual Studio辅助控件,例如我们通常会用到的“上一步”按钮,标签文本,超链文本,滑动条,进度条等等。这些Visual Studio辅助控件,极大地丰富了Ribbon界面的表现力。
如下代码演示了Visual Studio辅助控件的创建过程:
- // 添加“上一步”按钮
- CMFCRibbonPanel* pPanel1 = pCategory->AddPanel(_T("Undo"));
- CMFCRibbonUndoButton* pBtn1 = new CMFCRibbonUndoButton(ID_RIBBON_OBTN_1, _T("Undo"), 0, 0);
- // 为返回按钮添加可以返回的动作
- for (int i = 0; i < 10; i++)
- {
- CString str;
- str.Format(_T("Action %d"), i + 1);
- pBtn1->AddUndoAction(str);
- }
- pPanel1->Add(pBtn1);
- // 添加文本标签
- CMFCRibbonPanel* pPanel2 = pCategory->AddPanel(_T("Label"));
- pPanel2->Add(new CMFCRibbonLabel(_T("Label 1")));
- pPanel2->Add(new CMFCRibbonLabel(_T("Label 2")));
- pPanel2->Add(new CMFCRibbonLabel(_T("Label 3")));
- // 在面板中添加一个分隔符
- pPanel2->Add(new CMFCRibbonSeparator());
- // 多行文本标签
- pPanel2->Add(new CMFCRibbonLabel(_T("This is a multi-line label"), TRUE));
- // 添加超链标签
- CMFCRibbonPanel* pPanel3 = pCategory->AddPanel(_T("Hyperlink"));
- // 写mail给我啊
- pPanel3->Add(new CMFCRibbonLinkCtrl(ID_RIBBON_OBTN_2, _T("Send e-mail"),
_T("mailto:chenlq@live.com")));- // 欢迎访问我的blog
- pPanel3->Add(new CMFCRibbonLinkCtrl(ID_RIBBON_OBTN_3, _T("Visit site"),
_T("http://space.itpub.net/17237043/")));- pPanel3->Add(new CMFCRibbonLinkCtrl(ID_RIBBON_OBTN_4, _T("Launch Notepad"), _T("notepad")));
- // 滑动条
- CMFCRibbonPanel* pPanel4 = pCategory->AddPanel(_T("Sliders"));
- pPanel4->SetCenterColumnVert();
- pPanel4->Add(new CMFCRibbonLabel(_T("Simple Slider:")));
- pPanel4->Add(new CMFCRibbonSlider(ID_RIBBON_OBTN_5, 70 /* Slider width */));
- pPanel4->Add(new CMFCRibbonSeparator());
- pPanel4->Add(new CMFCRibbonLabel(_T("Slider with Buttons:")));
- CMFCRibbonSlider* pBtn6 = new CMFCRibbonSlider(ID_RIBBON_OBTN_6, 70 /* Slider width */);
- // 设置缩放按钮
- pBtn6->SetZoomButtons();
- pBtn6->SetRange(0, 100);
- pBtn6->SetPos(50);
- pPanel4->Add(pBtn6);
- // 进度条
- CMFCRibbonPanel* pPanel5 = pCategory->AddPanel(_T("Progress Bars"));
- pPanel5->SetCenterColumnVert();
- // 简单进度条
- pPanel5->Add(new CMFCRibbonLabel(_T("Simple Progress:")));
- pPanel5->Add(new CMFCRibbonProgressBar(ID_RIBBON_OBTN_7, 100 /* Bar width */));
- pPanel5->Add(new CMFCRibbonButton(ID_RIBBON_OBTN_8, _T("Show Progress 1")));
- pPanel5->Add(new CMFCRibbonSeparator());
- pPanel5->Add(new CMFCRibbonLabel(_T("Infinite Progress:")));
- CMFCRibbonProgressBar* pBtn9 = new CMFCRibbonProgressBar(ID_RIBBON_OBTN_9, 100 /* Bar width */);
- // 设置为无限模式,表示动作在进行,但是没有明确的进度
- pBtn9->SetInfiniteMode();
- pPanel5->Add(pBtn9);
- pPanel5->Add(new CMFCRibbonButton(ID_RIBBON_OBTN_10, _T("Show Progress 2")));