How can I show map on gMapControl? - c#

My problem is I can not see any thing on form when I run application. This my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GMap;
using GMap.NET;
using GMap.NET.WindowsForms;
namespace Gmap_tesx
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e1)
{
try
{
System.Net.IPHostEntry e =
System.Net.Dns.GetHostEntry("www.google.com");
}
catch
{
gMapControl1.Manager.Mode = AccessMode.CacheOnly;
MessageBox.Show("No internet connection avaible, going to CacheOnly mode.",
"GMap.NET - Demo.WindowsForms", MessageBoxButtons.OK,
MessageBoxIcon.Warning);
}
// config map
GMaps.Instance.Mode = AccessMode.ServerAndCache;
// gMapControl1.CacheLocation = Application.StartupPath + "data.gmdp";
GMaps g = new GMaps();
gMapControl1.MapType = MapType.GoogleSatellite;
gMapControl1.MaxZoom = 6;
gMapControl1.MinZoom = 1;
gMapControl1.Zoom = gMapControl1.MinZoom + 1;
gMapControl1.Position = new PointLatLng(54.6961334816182,
25.2985095977783);
// map events
gMapControl1.OnCurrentPositionChanged += new
CurrentPositionChanged(gMapControl1_OnCurrentPositionChanged);
gMapControl1.OnTileLoadStart += new TileLoadStart(gMapControl1_OnTileLoadStart);
gMapControl1.OnTileLoadComplete += new
TileLoadComplete(gMapControl1_OnTileLoadComplete);
gMapControl1.OnMarkerClick += new MarkerClick(gMapControl1_OnMarkerClick);
gMapControl1.OnMapZoomChanged += new MapZoomChanged(gMapControl1_OnMapZoomChanged);
gMapControl1.OnMapTypeChanged += new MapTypeChanged(gMapControl1_OnMapTypeChanged);
gMapControl1.MouseMove += new MouseEventHandler(gMapControl1_MouseMove);
gMapControl1.MouseDown += new MouseEventHandler(gMapControl1_MouseDown);
gMapControl1.MouseUp += new MouseEventHandler(gMapControl1_MouseUp);
gMapControl1.OnMarkerEnter += new MarkerEnter(gMapControl1_OnMarkerEnter);
gMapControl1.OnMarkerLeave += new MarkerLeave(gMapControl1_OnMarkerLeave);
}
private void gMapControl1_OnCurrentPositionChanged(PointLatLng point)
{
}
private void gMapControl1_OnMarkerLeave(GMapMarker item)
{
}
private void gMapControl1_OnMarkerEnter(GMapMarker item)
{
}
private void gMapControl1_MouseUp(object sender, MouseEventArgs e)
{
}
private void gMapControl1_MouseDown(object sender, MouseEventArgs e)
{
}
private void gMapControl1_MouseMove(object sender, MouseEventArgs e)
{
}
private void gMapControl1_OnMapTypeChanged(MapType type)
{
}
private void gMapControl1_OnMapZoomChanged()
{
}
private void gMapControl1_OnMarkerClick(GMapMarker item, MouseEventArgs e)
{
}
private void gMapControl1_OnTileLoadComplete(long ElapsedMilliseconds)
{
}
private void gMapControl1_OnTileLoadStart()
{
}
}
}

Related

How do I make a winform minimize animation

How can I add an animation to Form's Minimize?
Here's an example: https://i.gyazo.com/fddb5bf0ce748ae69320ae08e1986ac3.mp4
I am using Winforms C#
EDITED:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TestMinimize
{
public partial class Form1 : Form
{
System.Windows.Forms.Timer t = new System.Windows.Forms.Timer();
System.Windows.Forms.Timer t1 = new System.Windows.Forms.Timer();
bool Minimized;
public Form1()
{
InitializeComponent();
t.Interval = 2; // specify interval time as you want
t.Tick += new EventHandler(timer_Tick);
this.SizeChanged += new EventHandler(this_SizeChanged);
t1.Interval = 1;
t1.Tick += new EventHandler(timer1_Tick);
t1.Start();
}
private void this_SizeChanged(object source, EventArgs e)
{
if (this.WindowState == FormWindowState.Normal)
{
Minimized = false;
}
}
private void timer_Tick(object source, EventArgs e)
{
this.Height = this.Height-8;
if (this.Height == 39)
{
t.Stop();
t.Enabled = false;
this.WindowState = FormWindowState.Minimized;
Minimized = true;
}
}
private void timer1_Tick(object source, EventArgs e)
{
if(Minimized==false && t.Enabled == false)
{
this.Height = 221;
}
}
private void button1_Click(object sender, EventArgs e)
{
t.Start();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}

serialport1 does not exist in context

using System.Collections.Generic;
using System.ComponentModel;
using System;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
namespace WindowsFormsApplication21
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
button1.BackColor = Color.Red;
label1.Text = " OCCUPIED";
}
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
this.Invoke(new EventHandler(DoUpdate));
}
private void DoUpdate(object s, EventArgs e)
{
string InputString = serialPort1.ReadExisting();
string[] data = InputString.Split(',');
textBox1.Text = data[0];
textBox2.Text = data[1];
int b;
int d;
bool result = Int32.TryParse(data[0], out b);
bool sonuc = Int32.TryParse(data[1], out d);
if (result)
{
if (b < 224)
{
button1.BackColor = Color.Red;
label1.Text = " OCCUPIED";
}
else
{
button1.BackColor = Color.Lime;
label1.Text = "AVAILABLE";
}
}
if (sonuc)
{
if (d< 224)
{
button1.BackColor = Color.Red;
label1.Text = " OCCUPIED";
}
else
{
button1.BackColor = Color.Lime;
label1.Text = "AVAILABLE";
}
}
int b = Int16.Parse(a);
textBox1.Text= a.ToString();*/
private void button3_Click(object sender, EventArgs e)
{
listBox1.Visible = true;
listBox1.Items.Add("Değerler alınıyor!");
if (!serialPort1.IsOpen)
{
serialPort1.PortName = "COM11";
serialPort1.Open();
}
}
private void button4_Click(object sender, EventArgs e)
{
serialPort1.Close();
listBox1.Items.Add("Durduruldu!");
}
}
}
I am getting an error:
"serialport1 does not exist in context"
What can l do? Whenever I want to compile I get the above mention error.
Do I have to add any library?
I am using visual Studio 2010

Graph plotting C#

I am working on an interface in C#, which reads data from the serial port and displays it on a graph. I wrote the following code, but the graph doesn't display anything. What is wrong? I don't know exactly what should I modify.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public long rt = 0;
string dataReceived = string.Empty;
private delegate void SetTextDeleg(string text);
// public string kp, kd, ki;
public int distanta;
public string potentiometru;
public Form1()
{
InitializeComponent();
this.chart1.ChartAreas[0].AxisX.Minimum = 0;
this.chart1.ChartAreas[0].AxisY.Minimum = 0;
this.chart1.ChartAreas[0].AxisY.Maximum = 55;
}
private void Connect_button_Click(object sender, EventArgs e)
{
if (serialPort1.IsOpen)
{
Connect_button.Enabled = false;
}
serialPort1.BaudRate = 9600;// Convert.ToUInt16(comboBox1.Text);
serialPort1.PortName = comboBox3.Text;
serialPort1.DataBits = 8;
serialPort1.StopBits = (System.IO.Ports.StopBits)2;
timer1.Start();
serialPort1.Open();
}
private void Sent_Button_Click(object sender, EventArgs e)
{
// kp = Convert.ToString(Kp_textbox.Text);
//kd = Convert.ToString(Kd_textbox.Text);
//ki = Convert.ToString(Ki_textbox.Text);
//serialPort1.Write(kp);
//serialPort1.Write(ki);
//serialPort1.Write(kd);
//string transmit = "$kp$" + kp + "$kd$" + kd + "$ki$" + ki;
// $kp$0.25
}
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
try
{
string x = serialPort1.ReadLine();
this.BeginInvoke(new SetTextDeleg(DataReceived), new object[] { x });
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void DataReceived(string data)
{
dataReceived = data.Trim();
if (rt < 2)
return;
if (dataReceived.Contains("."))
{
senzor_textbox.Text = dataReceived;
this.chart1.Series["Distance"].Points.AddXY(0, dataReceived);
}
else
{
potentiometru_textbox.Text = dataReceived;
this.chart1.Series["SetPoint"].Points.AddXY(0, dataReceived);
}
rt = 0;
}
private void button1_Click(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
rt++;
}
private void button2_Click(object sender, EventArgs e)
{
if(serialPort1.IsOpen)
serialPort1.Close();
}
}
}

Need to calculate when adding coin

I am building a vending machine and I am stuck on adding coins.
Coin should automatically be calculated when I click on the assigned button But Instead I am just getting the value inside textbox here's the code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace VendingMachine
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void operator_Click(object sender, EventArgs e)
{
new Form2().Show();
this.Hide();
}
private void fiveP_Click(object sender, EventArgs e)
{
balance.Text = ((double)balance.Text + 0.05).ToString();
}
private void tenP_Click(object sender, EventArgs e)
{
balance.Clear();
balance.Text = balance.Text + "0.10";
}
private void twentyP_Click(object sender, EventArgs e)
{
balance.Clear();
balance.Text = balance.Text + "0.20";
}
private void fiftyP_Click(object sender, EventArgs e)
{
balance.Clear();
balance.Text = balance.Text + "0.50";
}
private void onePound_Click(object sender, EventArgs e)
{
balance.Clear();
balance.Text = balance.Text + "1.00";
}
private void twoPound_Click(object sender, EventArgs e)
{
balance.Clear();
balance.Text = balance.Text + "2.00";
}
}
}
Coin Class
using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
namespace VendingMachine
{
[Serializable]
internal class Coin : ISerializable, IComparable
{
public string coinName = "";
public double coinValue = 0.0;
public int coinBalance = 0;
public string Name
{
get { return this.coinName; }
set { this.coinName = value; }
}
public double Value
{
get { return this.coinValue; }
set { this.coinValue = value; }
}
public int Balance
{
get { return this.coinBalance; }
set { this.coinBalance = value; }
}
public Coin(string coin_name)
{ this.coinName = coin_name; }
public Coin(SerializationInfo info, StreamingContext ctxt)
{
this.coinValue = (double)info.GetValue("CoinValue", typeof(double));
this.coinName = (string)info.GetValue("CoinName", typeof(string));
}
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
{
info.AddValue("CoinValue", this.coinValue);
info.AddValue("CoinName", (object)this.coinName);
}
public int CompareTo(object obj)
{
if (obj is Coin)
return this.Value.CompareTo(((Coin)obj).Value);
else
throw new ArgumentException("object is not a Coin");
}
public static IComparer sortByCoinName()
{
return (IComparer)new Coin.sortByCoinNameHelper();
}
private class sortByCoinNameHelper : IComparer
{
int IComparer.Compare(object a, object b)
{
return ((Coin)a).Name.CompareTo(((Coin)b).Name);
}
}
}
}
if balance is the textbox you are working with, you are clearing it with the button press, erasing whatever was in it prior to the button press, so it will always be "" + whatever. also, you can't add strings like that, "1.00" + "2.00" == "1.002.00", != "3.00"
You are adding strings rather than numbers. You'll need to convert your strings into numbers to add them together, and you shouldn't clear your results first.
For example:
private void fiveP_Click(object sender, EventArgs e)
{
// balance.Clear(); <- You don't need this.
balance.Text = ((double)balance.Text + 0.05).ToString();
}
that is because you are using a string type for calculating.. there is a difference between calculating something and displaying it. in short:
float value = 0;
void print()
{
balance.Text = string.Format("{0:0.00}", value);
}
private void fiveP_Click(object sender, EventArgs e)
{
value += 0.05f;
print();
}
private void tenP_Click(object sender, EventArgs e)
{
value += 0.10f;
print();
}
private void twentyP_Click(object sender, EventArgs e)
{
value += 0.20f;
print();
}
private void fiftyP_Click(object sender, EventArgs e)
{
value += 0.50f;
print();
}
private void onePound_Click(object sender, EventArgs e)
{
value += 1;
print();
}
private void twoPound_Click(object sender, EventArgs e)
{
value += 2;
print();
}
in your code you are not adding numbers, example:
you have this code:
private void tenP_Click(object sender, EventArgs e)
{
balance.Clear();
balance.Text = balance.Text + "0.10";
}
the value of balance.Text = "0.10"
then, if the next code is executed:
private void fiftyP_Click(object sender, EventArgs e)
{
balance.Clear();
balance.Text = balance.Text + "0.50";
}
the value of balance.Text = "0.50"
the point is that your are trying to add strings not numbers and you are clearing your previous value

Usercontrol event firing multiple times asp.net c#

I've got the following code: -
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace Testing.Event_Delegate
{
public partial class WebForm1 : System.Web.UI.Page
{
WebUserControl2 QT2;
WebUserControl3 QT3;
DataTable dtQuestionSet;
protected void Page_Init(object sender, EventArgs e)
{
dtQuestionSet = (DataTable)Session["DataTableW"];
}
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack == false)
{
Session["Counter"] = 0;
Session["QuestionCount"] = 0;
Session["CompletedInsp"] = false;
}
//check to see if the inspection process is complete and display pass\fail and log. Else carry on.
if (Convert.ToBoolean(Session["CompletedInsp"]) == true)
{
//Response.Write("Failed");
ModalPopupExtender2.Show();
return;
}
// all controls need to be rendered every page postback otherwise the rest of the code loses scope.
QT2 = (WebUserControl2)this.LoadControl("WebUserControl2.ascx");
UC2BtnClickEvent.MyEvent2 += new UC2BtnClickEvent.OnMyEvent2(ChecKResult);
QT3 = (WebUserControl3)this.LoadControl("WebUserControl3.ascx");
UC2BtnClickEvent.MyEvent3 += new UC2BtnClickEvent.OnMyEvent3(ChecKResult);
PlaceHolder2.Controls.Add(QT2);
PlaceHolder2.Controls.Add(QT3);
QT2.Visible = false;
QT3.Visible = false;
if (IsPostBack == false)
{
dtQuestionSet = new DataTable();
MakeDataTabledtQuestionSet();
}
else
{
dtQuestionSet = (DataTable)Session["DataTableW"];
}
Session["DataTableW"] = dtQuestionSet;
}
void ChecKResult(object sender, EventArgs e, string strTextBox, string strMyDescription)
{
Label1.Text = "You Answered: - " + strMyDescription;
if (Convert.ToInt32(Session["Counter"]) > Convert.ToInt32(Session["QuestionCount"]))
{
Session["CompletedInsp"] = true;
}
else
{
//carry on with inspection
Session["Counter"] = Convert.ToInt32(Session["Counter"]) + 1;
dtQuestionSet = (DataTable)Session["DataTableW"];
RunInspection();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("WebForm1.aspx");
}
protected void cmdStartInspection_Click(object sender, EventArgs e)
{
Session["Counter"] = 0;
GetQuestions();
}
protected void GetQuestions()
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["PromptedInspConnectionString"].ConnectionString);
conn.Open();
SqlCommand cmd = new SqlCommand("test.GetQuestions", conn);
SqlDataReader dr = null;
cmd.CommandType = CommandType.StoredProcedure;
//cmd.Parameters.Add(new SqlParameter("#Block1", cmbBlock1.Text));
dr = cmd.ExecuteReader();
while (dr.Read())
{
DataRow drQuestions = dtQuestionSet.NewRow();
drQuestions["QuestionText"] = dr[1].ToString();
drQuestions["ExpectedResponse"] = dr[2].ToString();
drQuestions["QuestionType"] = dr[3].ToString();
dtQuestionSet.Rows.Add(drQuestions);
}
Session["DataTableW"] = dtQuestionSet;
Session["QuestionCount"] = dtQuestionSet.Rows.Count;
conn.Close();
RunInspection();
}
protected void RunInspection()
{
switch (dtQuestionSet.Rows[Convert.ToInt32(Session["counter"])][2].ToString())
{
case "1":
QT2.QuestionText = dtQuestionSet.Rows[0][0].ToString();//"I'm asking a question 1";
QT2.Visible = true;
break;
case "2":
QT3.QuestionText = dtQuestionSet.Rows[0][0].ToString();//"I'm asking a question 2";
QT3.Visible = true;
break;
}
}
private void MakeDataTabledtQuestionSet()
{
dtQuestionSet.Columns.Add("QuestionText");
dtQuestionSet.Columns.Add("ExpectedResponse");
dtQuestionSet.Columns.Add("QuestionType");
}
}
}
When I click on the button on a usercontrol with the code: -
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Testing.Event_Delegate
{
public partial class WebUserControl2 : System.Web.UI.UserControl
{
string questionAsked;
public string QuestionText
{
set { questionAsked = value; }
get { return questionAsked; }
}
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = QuestionText;
TextBox1.Focus();
}
protected void Button1_Click(object sender, EventArgs e)
{
UC2BtnClickEvent bEvent = new UC2BtnClickEvent();
bEvent.onRefresh2Event3(sender, e, TextBox1.Text, TextBox1.Text );
TextBox1.Text = "";
}
}
}
It runs the procedure CheckResults 3 times on the aspx page when I only need it to run once.
UC2BtnClickEvent.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Testing.Event_Delegate
{
public class UC2BtnClickEvent
{
public delegate void OnMyEvent2(object sender, EventArgs e, string strTextBox, string strMyDescription);
public static event OnMyEvent2 MyEvent2;
public virtual void onRefresh2Event2(object sender, EventArgs e, string strTextBox, string strMyDescription)
{
if (MyEvent2 != null)
{
MyEvent2(sender, e, strTextBox, strMyDescription);
}
}
public delegate void OnMyEvent3(object sender, EventArgs e, string strTextBox, string strMyDescription);
public static event OnMyEvent3 MyEvent3;
public virtual void onRefresh2Event3(object sender, EventArgs e, string strTextBox, string strMyDescription)
{
if (MyEvent3 != null)
{
MyEvent3(sender, e, strTextBox, strMyDescription);
}
}
}
}
What have I done wrong to make this happen please as it should only run once.

Categories