Click here to Skip to main content
14,362,554 members
   

C#

 
GeneralRe: [VS2008 - Compact Framework] How to prevent a closed form from been disposed Pin
lw@zi 30-Sep-19 3:04
professional lw@zi 30-Sep-19 3:04 
GeneralRe: [VS2008 - Compact Framework] How to prevent a closed form from been disposed Pin
steve_949661330-Sep-19 2:39
professionalsteve_949661330-Sep-19 2:39 
GeneralRe: [VS2008 - Compact Framework] How to prevent a closed form from been disposed Pin
#realJSOP30-Sep-19 3:02
mve#realJSOP30-Sep-19 3:02 
GeneralRe: [VS2008 - Compact Framework] How to prevent a closed form from been disposed Pin
steve_949661330-Sep-19 3:30
professionalsteve_949661330-Sep-19 3:30 
AnswerRe: [VS2008 - Compact Framework] How to prevent a closed form from been disposed Pin
lw@zi 27-Sep-19 2:08
professional lw@zi 27-Sep-19 2:08 
GeneralRe: [VS2008 - Compact Framework] How to prevent a closed form from been disposed Pin
steve_949661327-Sep-19 2:52
professionalsteve_949661327-Sep-19 2:52 
GeneralRe: [VS2008 - Compact Framework] How to prevent a closed form from been disposed Pin
lw@zi 30-Sep-19 0:02
professional lw@zi 30-Sep-19 0:02 
GeneralRe: [VS2008 - Compact Framework] How to prevent a closed form from been disposed Pin
steve_949661330-Sep-19 3:18
professionalsteve_949661330-Sep-19 3:18 
In the form there are:

3 BeeMobile.TransparentControls.TImageButton
2 BeeMobile.TransparentControls.TLabel
2 BeeMobile.RoundTextBox.RoundTextBox
1 BeeMobile.MonthCalendar.MonthCalendar
1 BeeMobile.iWheel.iWheel
2 System.Windows.Forms.Timer

For what I know, I do not dispose any control voluntarily...

Here is the code on the form:

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

//alias
using LangD = SA7.Cl_LangData;
using Gr = SA7.Cl_Graphics;
using Globals = SA7.Cl_Globals;

namespace SA7
{
  public partial class FormDateTime : Form
  {

    private bool FormDateTime_FirstShow = true;     // flag: first call to FormDateTime_Load

    Cl_DateTime Tempo = new Cl_DateTime();


    public struct SYSTEMTIME
    {
      public short wYear;
      public short wMonth;
      public short wDayOfWeek;
      public short wDay;
      public short wHour;
      public short wMinute;
      public short wSecond;
      public short wMilliseconds;
    }

    //functions to read and to set time
    [DllImport("coredll.dll")]
    private extern static void GetSystemTime(ref SYSTEMTIME lpSystemTime);

    [DllImport("coredll.dll")]
    private extern static uint SetSystemTime(ref SYSTEMTIME lpSystemTime);

    //---------------------------------------------------------------------------------

    public FormDateTime()
    {
      InitializeComponent();
      this.Location = new Point((800 - this.Width) / 2, (480 - this.Height) / 2);
    }
    //---------------------------------------------------------------------------------.

    private void FormDateTime_Load(object sender, EventArgs e)
    {
      if (FormDateTime_FirstShow) {

        FormDateTime_FirstShow = false;
      }

      CtrlsDesc();
      UpdateDateTime();
      ExitTr.Enabled = true;
    }
    //---------------------------------------------------------------------------------

    private void FormDateTime_Paint(object sender, PaintEventArgs e)
    {
      //draw window border
      Gr.DrawFrContour(e, 0, 1, 1, this.Width - 1, this.Height - 1);
    }
    //---------------------------------------------------------------------------------

    //update strings
    public void CtrlsDesc()
    {
      AbortBt.Text = FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinExit);
      UpdateBt.Text = FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinUpadateTime);
      DateLb.Text = FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinDate);
      TimeLb.Text = FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinTime);
      OKVBt.Text = FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinOK);
    }
    //---------------------------------------------------------------------------------

    // update controls with date and time
    private void UpdateDateTime()
    {
      DateTime tmp;

      tmp = DateTime.Now;
      DateRTB.Text = string.Format("{0:00} {1} {2}", tmp.Day, GetMonthStr(tmp.Month), tmp.Year);
      TimeRTB.Text = string.Format("{0:00}:{1:00}:{2:00}", tmp.Hour, tmp.Minute, tmp.Second);

      UpdateDate();
      UpdateTime();
    }
    //---------------------------------------------------------------------------------
    private void UpdateDate()
    {
      DateTime tmp;

      tmp = DateTime.Now;

      MonthCalendar.CurrentMonth = tmp;
      MonthCalendar.SelectedDate = tmp;
    }
    //---------------------------------------------------------------------------------
    private void UpdateTime()
    {
      DateTime tmp;

      tmp = DateTime.Now;

      ((BeeMobile.iWheel.TextCylinder)TimeIW.Cylinders[0]).SelectedIndex = tmp.Hour;
      ((BeeMobile.iWheel.TextCylinder)TimeIW.Cylinders[1]).SelectedIndex = tmp.Minute;
      ((BeeMobile.iWheel.TextCylinder)TimeIW.Cylinders[2]).SelectedIndex = tmp.Second;
    }
    //---------------------------------------------------------------------------------

    // get month in text format
    private string GetMonthStr(Int32 mese)
    {
      switch (mese)
      {
        case 1:
          return FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinGen);

        case 2:
          return FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinFeb);

        case 3:
          return FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinMaz);

        case 4:
          return FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinApr);

        case 5:
          return FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinMag);

        case 6:
          return FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinGiu);

        case 7:
          return FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinLug);

        case 8:
          return FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinAgo);

        case 9:
          return FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinSet);

        case 10:
          return FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinOtt);

        case 11:
          return FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinNov);

        case 12:
          return FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinDic);

        default:
          break;
      }

      return "";
    }
    //---------------------------------------------------------------------------------

    //accept the changes
    private void UpdateBt_Click(object sender, EventArgs e)
    {
      DateTime tmp;

      ExitTr.Interval = Globals.EXIT_TR_TIME;

      // Call the native GetSystemTime method
      // with the defined structure.
      SYSTEMTIME systime = new SYSTEMTIME();
      GetSystemTime(ref systime);

      tmp = DateTime.Parse(string.Format("{0:00}/{1:00}/{2:00} {3:00}:{4:00}:{5:00}", MonthCalendar.SelectedDate.Month, MonthCalendar.SelectedDate.Day, MonthCalendar.SelectedDate.Year, ((BeeMobile.iWheel.TextCylinder)TimeIW.Cylinders[0]).SelectedIndex, ((BeeMobile.iWheel.TextCylinder)TimeIW.Cylinders[1]).SelectedIndex, ((BeeMobile.iWheel.TextCylinder)TimeIW.Cylinders[2]).SelectedIndex));
      tmp = tmp.ToUniversalTime();

      // Set the system clock
      systime.wDay = (short)tmp.Day;
      systime.wMonth = (short)tmp.Month;
      systime.wYear = (short)tmp.Year;
      systime.wHour = (short)tmp.Hour;
      systime.wMinute = (short)tmp.Minute;
      systime.wSecond = (short)tmp.Second;

      SetSystemTime(ref systime);

      // timer to close the form with a little delay to avoid the user
      // to push a button in the form below (touchscreen panel) 
      UpdateTr.Enabled = true;
    }
    //---------------------------------------------------------------------------------
    private void UpdateTr_Tick(object sender, EventArgs e)
    {
      UpdateTr.Enabled = false;
      Close();
    }
    //---------------------------------------------------------------------------------

    //close the windows
    private void AbortBt_Click(object sender, EventArgs e)
    {
      ExitTr.Enabled = false;
      Close();
    }
    //---------------------------------------------------------------------------------

    private void OKVBt_Click(object sender, EventArgs e)
    {
      ExitTr.Interval = Globals.EXIT_TR_TIME;
      
      TimeRTB.Text = string.Format("{0:00}:{1:00}:{2:00}", ((BeeMobile.iWheel.TextCylinder)TimeIW.Cylinders[0]).SelectedIndex, ((BeeMobile.iWheel.TextCylinder)TimeIW.Cylinders[1]).SelectedIndex, ((BeeMobile.iWheel.TextCylinder)TimeIW.Cylinders[2]).SelectedIndex);

      DateLb.Visible = true;
      TimeLb.Visible = true;
      DateRTB.Visible = true;
      TimeRTB.Visible = true;
      AbortBt.Visible = true;
      UpdateBt.Visible = true;
      MonthCalendar.Visible = false;
      TimeIW.Visible = false;
      OKVBt.Visible = false;
    }
    //---------------------------------------------------------------------------------

    //a date has been selected
    private void MonthCalendar_SelectedDateChanged(object sender, EventArgs e)
    {
      ExitTr.Interval = Globals.EXIT_TR_TIME;

      MonthCalendar.Visible = false;
      DateRTB.Text = String.Format("{0:00} {1} {2}", MonthCalendar.SelectedDate.Day, GetMonthStr(MonthCalendar.SelectedDate.Month), MonthCalendar.SelectedDate.Year);
      DateLb.Visible = true;
      TimeLb.Visible = true;
      DateRTB.Visible = true;
      AbortBt.Visible = true;
      UpdateBt.Visible = true;
      TimeIW.Visible = false;
      OKVBt.Visible = false;
      TimeRTB.Visible = true;
    }
    //---------------------------------------------------------------------------------

    //click on time
    private void TimeRTB_Click(object sender, EventArgs e)
    {
      ExitTr.Interval = Globals.EXIT_TR_TIME;

      // update the displayed time
      UpdateTime();
      DateLb.Visible = false;
      TimeLb.Visible = false;
      DateRTB.Visible = false;
      TimeRTB.Visible = false;
      AbortBt.Visible = false;
      UpdateBt.Visible = false;
      MonthCalendar.Visible = false;
      TimeIW.Visible = true;
      OKVBt.Visible = true;
    }
    //---------------------------------------------------------------------------------

    //click on date
    private void DateRTB_Click(object sender, EventArgs e)
    {
      ExitTr.Interval = Globals.EXIT_TR_TIME;
      
      // update the displayed date
      UpdateDate();
      DateLb.Visible = false;
      TimeLb.Visible = false;
      DateRTB.Visible = false;
      TimeRTB.Visible = false;
      AbortBt.Visible = false;
      UpdateBt.Visible = false;
      TimeIW.Visible = false;
      OKVBt.Visible = false;
      MonthCalendar.Visible = true;
    }
    //---------------------------------------------------------------------------------

    private void FormDateTime_Click(object sender, EventArgs e)
    {
      ExitTr.Interval = Globals.EXIT_TR_TIME;
    }
    //---------------------------------------------------------------------------------

    private void ExitTr_Tick(object sender, EventArgs e)
    {
      ExitTr.Enabled = false;
      Close();
    }
    //---------------------------------------------------------------------------------

  }
}


The timer ExitTr is used to close the form if the user lets the form opened without doing anything for some time. It is started at the form show.

The timer UpdateTr is used to close the form with a short delay.

Now that I copy here my code I notice that when I close the form in UpdateTr I don't stop the running timer ExitTr, this could be a problem?
QuestionHow to press a key with TranslateMessage Pin
Member 1305673426-Sep-19 2:42
memberMember 1305673426-Sep-19 2:42 
AnswerRe: How to press a key with TranslateMessage Pin
Richard Deeming26-Sep-19 3:02
mveRichard Deeming26-Sep-19 3:02 
GeneralRe: How to press a key with TranslateMessage Pin
Member 1305673426-Sep-19 3:10
memberMember 1305673426-Sep-19 3:10 
GeneralRe: How to press a key with TranslateMessage Pin
Richard Deeming26-Sep-19 3:14
mveRichard Deeming26-Sep-19 3:14 
AnswerRe: How to press a key with TranslateMessage Pin
OriginalGriff26-Sep-19 3:23
protectorOriginalGriff26-Sep-19 3:23 
QuestionChanging many projects from AnyCPU to x64 Pin
Bernhard Hiller24-Sep-19 23:04
memberBernhard Hiller24-Sep-19 23:04 
AnswerRe: Changing many projects from AnyCPU to x64 Pin
OriginalGriff24-Sep-19 23:29
protectorOriginalGriff24-Sep-19 23:29 
GeneralRe: Changing many projects from AnyCPU to x64 Pin
harold aptroot25-Sep-19 0:33
memberharold aptroot25-Sep-19 0:33 
GeneralRe: Changing many projects from AnyCPU to x64 Pin
Bernhard Hiller25-Sep-19 1:11
memberBernhard Hiller25-Sep-19 1:11 
AnswerRe: Changing many projects from AnyCPU to x64 Pin
jkirkerx25-Sep-19 14:47
professionaljkirkerx25-Sep-19 14:47 
AnswerRe: Changing many projects from AnyCPU to x64 Pin
Richard MacCutchan25-Sep-19 22:43
protectorRichard MacCutchan25-Sep-19 22:43 
GeneralRe: Changing many projects from AnyCPU to x64 Pin
Bernhard Hiller26-Sep-19 22:43
memberBernhard Hiller26-Sep-19 22:43 
GeneralRe: Changing many projects from AnyCPU to x64 Pin
harold aptroot28-Sep-19 0:35
memberharold aptroot28-Sep-19 0:35 
GeneralRe: Changing many projects from AnyCPU to x64 Pin
Bernhard Hiller29-Sep-19 22:48
memberBernhard Hiller29-Sep-19 22:48 
AnswerRe: Changing many projects from AnyCPU to x64 Pin
AntGamble15-Oct-19 22:40
memberAntGamble15-Oct-19 22:40 
QuestionHow to properly close a JSON Post using RestSharp? Pin
mlong3024-Sep-19 14:25
membermlong3024-Sep-19 14:25 
AnswerRe: How to properly close a JSON Post using RestSharp? Pin
BillWoodruff24-Sep-19 17:06
mveBillWoodruff24-Sep-19 17:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.