0

I have seen a lot examples with dialog creation, like:

 Dialog
 Title "Title"
 Width 198 Height 52
 Control Button
 Title "Обзор"
 Width 50 Height 15
 Position 133, 6
 ID 5001
 Calling SetTextEditFolder
 Control Button
 Title "Создать"
 Position 15, 28
 Width 50 Height 15
 Calling CallforYes

But is just a static dialog. It's possible to dinnamically add anf remove controls from dialog? For example i want press button or select value in list edit and change set of controls in dialog.
Any advises?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jul 23, 2016 at 21:22

2 Answers 2

2

It's not really possible to dynamically create a dialog in MapBasic unfortunately. I had thought it may be possible to use the Run Command statement to run a dynamically created dialog command but testing confirmed this wasn't possible. The Run Command statement is apparently limited to commands you can run from the MapBasic window from within MapInfo.

This means that the only way to do this is to create as many controls as you may need and keep them hidden unless required at runtime. You will probably also want to determine the size of the dialog box based on the number of controls you are going to show - this can also be resolved at runtime.

Once you know how many controls you are going to need then you can go and unhide them, size your dialog, and position any other controls (e.g. ok button) appropriately.

See this post for a bit more info.

answered Jul 25, 2016 at 8:21
1
  • Your aswer make me sad. But i cant find another solution. Thanks. Commented Jul 26, 2016 at 11:29
2

You can create Dialogs in .NET with Visual Studio (VB.NET or C#) and use such controls in your MapBasic.

Check your MapBasic folder Samples\DOTNET\NAMEDVIEWS to see an example.

This is a simple example I use in my application:

C# Code:

internal partial class FormDatePicker: Form
{
 /// <summary>
 /// Create new form, with specified initial date
 /// </summary>
 /// <param name="intialDate">The initially selected day</param>
 public FormDatePicker(DateTime intialDate, string caption)
 {
 InitializeComponent();
 this.Text = caption;
 this.SelectedDate = intialDate;
 datePicker.MaxSelectionCount = 1;
 datePicker.TodayDate = DateTime.Now.Date;
 datePicker.DateChanged += new DateRangeEventHandler(this.datePicker_DateChanged);
 datePicker.MouseDown += new MouseEventHandler(this.datePicker_MouseDown);
 this.Shown += new EventHandler(this.SizeForm);
 this.Size = new Size(178, 162);
 }
 /// <summary>
 /// Property holding selected day
 /// </summary>
 public DateTime SelectedDate { get; private set; }
 /// <summary>
 /// EventHandler when user selects a day
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void datePicker_DateChanged(object sender, DateRangeEventArgs e)
 {
 datePicker.MouseDown -= new MouseEventHandler(this.datePicker_MouseDown);
 this.SelectedDate = datePicker.SelectionStart;
 this.DialogResult = System.Windows.Forms.DialogResult.OK;
 this.Close();
 }
 private void datePicker_MouseDown(object sender, MouseEventArgs e)
 {
 datePicker.DateChanged -= new DateRangeEventHandler(this.datePicker_DateChanged);
 this.SelectedDate = datePicker.SelectionStart;
 this.DialogResult = System.Windows.Forms.DialogResult.OK;
 this.Close();
 }
 /// <summary>
 /// Set form to proper size when shown the first time
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void SizeForm(object sender, EventArgs e)
 {
 ClientSize = datePicker.Size;
 }
}
public static class DatePicker
{
 /// <summary>
 /// Shows a .NET MonthCalendar Dialog where user can select a date.
 /// </summary>
 /// <param name="initial">The initial date when MonthCalendar shows up</param>
 /// <returns>The selected day in format "yyyyMMdd"</returns>
 public static int PickDate(int initial, string caption)
 {
 FormDatePicker form = new FormDatePicker(DateTime.ParseExact(initial.ToString(), "yyyyMMdd", CultureInfo.InvariantCulture), caption);
 if ( form.ShowDialog() == DialogResult.OK )
 return Convert.ToInt32(form.SelectedDate.ToString("yyyyMMdd"));
 else
 return initial;
 }
}

And the call in MapBasic:

Declare Method PickDate Class "MyApp.DatePicker" Lib "MyApp.dll" (ByVal initial As Integer, ByVal caption As String) As Integer
Function SelectDate(ByVal initial As Date, ByVal caption As String) As Date
 SelectDate = NumberToDate(PickDate(initial, caption))
End Function
answered Jul 27, 2016 at 8:03

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.