GXT MessageBox - customize buttons - gxt

how can i customize the buttons in gxt MessageBox.
so instead of Ok and cancel i can have different lables

((Button)box.getDialog().getButtonBar().getItem(0)).setText("changed");

MessageBox is just a helper class for creating common Dialogs with, for example, YESOK buttons and others.
MessageBox.show() is:
public void show() {
dialog = getDialog();
dialog.show();
}
getDialog() - creates dialog with your predefined parameters.
If you want to really customize your buttons - set icons, change text, add more buttons like "print, export..." - extend Dialog, call setButtons(""); in constructor and add your buttons addButton(new MyCustomButton);
Also, you are free to get details in MessageBox source.

Related

MS Visual Studio 2013 MFC Application: Create a text box for messaging / output service

Using MS VC, I've created a "Dialog based" MFC Application. Let's call it MyApp1. I simply want to add some kind of "box" to my dialog to display text. I tried to add an "Edit Control" and then printing to it via
var_set.SetCueBanner(_T("Test"), TRUE);
var_set is the variable of the Edit Control CEdit. This code is added in a function that is called when pressing a button in the dialog. E.g.
void MyApp1Dlg::OnBnClickedButton1()
{
var_set.SetCueBanner(_T("Test"), TRUE);
}
However, I think this is at least not the way an "Edit Control" should be used... So I tried with a "Static Text". To control it, I read to use
HWND hwndText = GetDlgItem(dlg, IDC_STATIC);
SetWindowText(hwndText, L"Test");
But I would have to use the ID of the dialog dlg which is not defined in MyApp1Dlg.cpp file. I found it in the MyApp1.cpp. Should I export that instance to MyApp1Dlg.cpp or is there another way to display text in my dialog? In the final application, I'd like to use it similar to a
printf("output: %g\n", xx);
command. Thanks for hints.
The SetCueBanner function is for setting a prompt into the edit control. If you want to set the actual text, use SetWindowText - it's part of the parent class CWnd so you would not find it in the CEdit documentation. This works for both edit and static controls, although a static control might also need a RedrawWindow before it shows the new text.
var_set.SetWindowText(_T("Test"));
OK, I got an answer:
First, define an "Edit Control" box. Let's call the ID IDC_EDIT1. Next, in one of the MyApp1Dlg.cpp functions, insert
CString str;
str.Format(_T("%d x %d"), .5, .4);
SetDlgItemText(IDC_EDIT1, str);
and mark the property "Read only" to True.

Hide Controls At Design-Time [duplicate]

I need to handle multiple panels, containing variuous data masks. Each panel shall be visible using a TreeView control.
At this time, I handle the panels visibility manually, by making the selected one visible and bring it on top.
Actually this is not much confortable, especially in the UI designer, since when I add a brand new panel I have to resize every panel and then design it...
A good solution would be using a TabControl, and each panel is contained in a TabPage. But I cannot find any way to hide the TabControl buttons, since I already have a TreeView for selecting items.
Another solution would be an ipotethic "StackPanelControl", where the Panels are arranged using a stack, but I couldn't find it anywhere.
What's the best solution to handle this kind of UI?
You need a wee bit of Win32 API magic. The tab control sends the TCM_ADJUSTRECT message to allow the app to adjust the tab size. Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form.
You'll get the tabs at design time so you can easily switch between pages. The tabs are hidden at runtime, use the SelectedIndex or SelectedTab property to switch between "views".
using System;
using System.Windows.Forms;
class StackPanel : TabControl {
protected override void WndProc(ref Message m) {
// Hide tabs by trapping the TCM_ADJUSTRECT message
if (m.Msg == 0x1328 && !DesignMode) m.Result = (IntPtr)1;
else base.WndProc(ref m);
}
}
A good solution would be using a TabControl, and each panel is contained in a TabPage.
But I cannot find any way to hide the TabControl buttons, since I already have a
TreeView for selecting items.
For the above,
You need to set the following properties of TabControl.
tabControl.Multiline = true;
tabControl.Appearance = TabAppearance.Buttons;
tabControl.ItemSize = new System.Drawing.Size(0, 1);
tabControl.SizeMode = TabSizeMode.Fixed;
tabControl.TabStop = false;

deriving Dialogs from a custom Dialog using mfc

I am trying to define a custom Dialog Template with certain members such as m_hImage, m_hName, and the m_hIcon in it. I want to then derive Dialogs using this Template.
I am not using any buttons(Ok,cancel etc.) in this template. Do i still need to declare or define OnOk(), OnCancel() etc.
Can anybody tell me what are the other methods I need to declare in this template class?
My goal is to just prepare this template dialog so that each dialog derived from this template contains a icon on the title bar (m_hIcon) , the image (m_hImage) on the upper left corner, and the image name (m_hName) on the upper right corner of dialog.
No, you need not to override any of the methods. You may however need to override OnInitDialog, otherwise you won't have any dialog initialization. This is the overridden method where you can setup the icon for dialog.

How do I make MFC checkbox read-only but keep text enabled?

It seems that disabling a checkbox through the Disabled property also grays out the caption. Does anyone know how to keep the caption enabled but disable input?
EDIT
Based on Paul's idea, I've done the following (now that I figured out that the static label and checkbox has a transparent property).
Added a couple checkboxes.
Set the checkbox captions to nothing.
Set checkbox transparent property to true.
Add a couple labels beside checkbox.
Change transparent property of labels to true.
Expand the checkboxes to encompass the label (so clicking on the label will trigger the check box to change).
But, this gives me very weird results. When I expand the checkbox over the label, it covers the label even though both are transparent. Again, I'm new to MFC (I'm a C# guy) so maybe I'm missing something.
Just override the onClick event and toggle the checkbox back to the way it was before.
void CMyDialog::OnBnClickedMyCheckBox()
{
m_myCheckBox.SetCheck(!m_myCheckBox.GetCheck());
}
Just make use of the Auto property, and leave it unchecked.
When clicking on it, it will not toggle any more, so basically it will be read-only, but still work fine as output.
Check Box Properties: Styles Auto Creates a check box that, when
selected, automatically toggles between checked and unchecked states.
You must set this property to True if you are using a group of check
boxes with Dialog Data Exchange.
Type: Bool, Default: True.
The quick and simple workaround is to not use the checkbox' text member (set it to ""), size down the checkbox to just the click-able square and simply place a label next to the checkbox.
To get a little fancier you could create a custom control that hosts a checkbox and a label which would enable reuse. It wold also be easier way to make the custom checkbox behave as expected for the end user e.g. being able to set the checkbox to selected or unselected when the label gets clicked as well as the checkbox itself. (The simple solution would not automatically relate the label and the checkbox. You could code that within the form but that might get ugly fast if you tend to reuse the paradigm.)
You could also look around for a 3rd-party checkbox control (there are numerous MFC UI libraries out there) but that might be overkill.
See this pseudo-layout:
You have this: (lone check box control)
[x "checkbox text"]
Lay it out like this: (label control aligned right next to the checkbox)
[x][label: "label text"]
Handle the clicked event of the label with something like:
void OnLabelClick(...) {
if (checkBox.Enabled)
checkBox.Checked = !checkBox.Checked;
}
You could un-select the box in the on-click function unless another condition exists.
void SetCheckBoxReadOnly(CButton* i_checkBox, bool i_readOnly)
{
if (!i_checkBox)
{
return;
}
// Clear/set "Auto" property
if (i_readOnly)
{
i_checkBox->ModifyStyle(BS_AUTOCHECKBOX, BS_CHECKBOX);
}
else
{
i_checkBox->ModifyStyle(BS_CHECKBOX, BS_AUTOCHECKBOX);
}
// Set a grey background for check square - looks like disabled :)
i_checkBox->SetState(i_readOnly ? TRUE : FALSE);
}

MessageBox in c#.net

How can I display a messagebox like the Microsoft error message in C#.net
The message box should have an OK button and an Show details button.
The Show details button should display the error details. Is there a built in class for this?
Thank you
There isn't a standard dialog to do this; you'll have to create your own Form and display it with a ShowDialog.
You can have the Click event of the 'Details' button change the size of the form and toggle the visibility of the details text.
There is no built in class available to do this.
you can create a custom form with Ok and Show Details button.
set height and width as per the need.
handle click event for the button with appropriate code.
create an instance of this form and use ShowDialog() method to show the dialog box

Resources