GMap.NET question - c#

i am trying to use GMap.NET to display a map using the following code
GMapControl g = new GMapControl();
GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerOnly;
g.Dock = DockStyle.Fill;
pnlMap.Controls.Add(g);
g.MapType = MapType.GoogleMap;
g.MaxZoom = 6;
g.MinZoom = 1;
g.Position = new PointLatLng(51.31835, 0.873866);
The issue is, the control loads but there is no visible map inside. Does anyone know what i might need to do
Thanks
edit:
the fix was this
public Form1()
{
InitializeComponent();
SuspendLayout();
GMapControl MainMap = new GMapControl();
{
MainMap.MapProvider = GMapProviders.YahooMap;
MainMap.Position = new PointLatLng(54.6961334816182, 25.2985095977783);
MainMap.MinZoom = 1;
MainMap.MaxZoom = 17;
MainMap.Zoom = 9;
MainMap.Dock = DockStyle.Fill;
}
Controls.Add(MainMap);
ResumeLayout(true);
}

Related

How to store certain variable values in a dynamically added control

I have a button which I added programmatically and I want to store certain unique information with every button. I have saved the Name and Text but is there a way to store another string to access later. Below is the code for my button and it's click event.
for (int i = bankaccountsDatagridview.Rows.Count - 1; i >= 0; i--)
{
string buttonName = "individualDepartmentBtn-" + i;
FontAwesome.Sharp.IconButton individualDepartmentBtn = new FontAwesome.Sharp.IconButton();
individualDepartmentBtn.BackColor = System.Drawing.Color.White;
individualDepartmentBtn.Cursor = System.Windows.Forms.Cursors.Hand;
individualDepartmentBtn.Dock = System.Windows.Forms.DockStyle.Top;
individualDepartmentBtn.FlatAppearance.BorderSize = 0;
individualDepartmentBtn.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Silver;
individualDepartmentBtn.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
individualDepartmentBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
individualDepartmentBtn.Flip = FontAwesome.Sharp.FlipOrientation.Normal;
individualDepartmentBtn.Font = new System.Drawing.Font("Roboto", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
individualDepartmentBtn.ForeColor = System.Drawing.Color.DimGray;
individualDepartmentBtn.IconChar = FontAwesome.Sharp.IconChar.None;
individualDepartmentBtn.IconColor = System.Drawing.Color.DimGray;
individualDepartmentBtn.IconSize = 25;
individualDepartmentBtn.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
individualDepartmentBtn.Margin = new System.Windows.Forms.Padding(10);
individualDepartmentBtn.Padding = new System.Windows.Forms.Padding(30, 0, 0, 0);
individualDepartmentBtn.Name = bankaccountsDatagridview.Rows[i].Cells[1].Value.ToString();
individualDepartmentBtn.Rotation = 0D;
individualDepartmentBtn.Size = new System.Drawing.Size(192, 30);
individualDepartmentBtn.TabIndex = 1;
individualDepartmentBtn.Text = bankaccountsDatagridview.Rows[i].Cells[1].Value.ToString();
individualDepartmentBtn.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
individualDepartmentBtn.UseVisualStyleBackColor = false;
navigationPanel.Controls.Add(individualDepartmentBtn);
individualDepartmentBtn.MouseDown += new System.Windows.Forms.MouseEventHandler(individualBankBtnDown);
}
Click Event:
private void individualBankBtnDown(object sender, MouseEventArgs e)
{
bankTitle = ((FontAwesome.Sharp.IconButton)sender).Name.ToString();
}
You can use the Tag property. For example:
individualDepartmentBtn.Tag = "My String";
You can store any object within Tag and not only strings.
Note that you could also use the var keyword and an object initializer to make your code a little bit more readable:
var individualDepartmentBtn = new FontAwesome.Sharp.IconButton
{
BackColor = System.Drawing.Color.White,
Cursor = System.Windows.Forms.Cursors.Hand,
Dock = System.Windows.Forms.DockStyle.Top,
...
};

WPF graph column graph

I am trying to set up a column graph with the time. Why is my graph not showing up on the main window?
I initialized the graph object like this :
private Chart graph = new Chart();
my chart functions are:
private void DrawTimeChart(string testName,double time)
{
Series sinSeries = new Series();
sinSeries.ChartType = SeriesChartType.Column;
sinSeries.Color = System.Drawing.Color.Blue;
sinSeries.BorderWidth = 2;
sinSeries.Points.AddXY(testName,time);
}
private void cnvChart_Loaded(object sender, RoutedEventArgs e)
{
System.Windows.Forms.Integration.WindowsFormsHost host = new System.Windows.Forms.Integration.WindowsFormsHost();
graph.Width = 250;
graph.Height = 250;
host.Child = graph;
// Add the chart to the canvas so it can be displayed.
this.cnvChart.Children.Add(host);
}
private void SetUpChart(Chart funcChart, int marginX, int marginY)
{
graph.Series.Clear();
graph.ChartAreas.Clear();
graph.ChartAreas.Add("Default" + new Random());
// Add a series with some data points.
funcChart.Width = 349;
funcChart.Height = 177;
funcChart.Location = new System.Drawing.Point(marginX, marginY);
funcChart.ChartAreas[0].AxisX.Title = "X";
funcChart.ChartAreas[0].AxisX.Interval = 1.0;
funcChart.ChartAreas[0].AxisX.Crossing = 0;
funcChart.ChartAreas[0].AxisX.LabelStyle.Format = "{0.0}";
funcChart.ChartAreas[0].AxisX.MajorGrid.LineWidth = 0;
funcChart.ChartAreas[0].AxisY.Title = "Y";
funcChart.ChartAreas[0].AxisY.Interval = 1.0;
funcChart.ChartAreas[0].AxisY.Crossing = 0;
funcChart.ChartAreas[0].AxisY.LabelStyle.Format = "{0.0}";
funcChart.ChartAreas[0].AxisY.MajorGrid.LineWidth = 0;
funcChart.ChartAreas[0].AxisX.Maximum = 6;
funcChart.ChartAreas[0].AxisX.Minimum = -6;
funcChart.ChartAreas[0].AxisY.Maximum = 7;
funcChart.ChartAreas[0].AxisY.Minimum = -7;
}
I'm calling the functions like this:
SetUpChart(graph,5,5);
DrawTimeChart("test1",time1);
in regards to XAML, that's how my canvas is written:
<Canvas x:Name="cnvChart" HorizontalAlignment="Right" Height="177"
Margin="0,242,392.333,0" VerticalAlignment="Top" Width="349"
Loaded="cnvChart_Loaded" RenderTransformOrigin="0.5,0.5"/>

C# Changing ForeColor of label hides everything else

I'm currently working on a file explorer.
Now I want to change the ForeColor of one label.
But as soon as I add the code for it everything else disappears.
lblpath.ForeColor = ColorTranslator.FromHtml("00ff00");
When I start the application Form1 will just be empty.
I don't know if I should post my code, because it's quite a bit and I don't know which parts would be relevant...
EDIT:
Method where I use this code:
private void initiateGUI()
{
this.Text = "Explorer";
this.BackColor = ColorTranslator.FromHtml("#1a1a1a");
oneup = new Button();
oneup.Location = new Point(455, 12);
oneup.Parent = this;
oneup.Visible = true;
oneup.MouseClick += oneup_click;
oneup.Text = "UP";
oneup.Width = 40;
oneup.Height = 20;
cmdrefresh = new Button();
cmdrefresh.Location = new Point(500, 12);
cmdrefresh.Parent = this;
cmdrefresh.Visible = true;
cmdrefresh.MouseClick += refresh_click;
cmdrefresh.Text = "Refresh";
cmdrefresh.Width = 55;
cmdrefresh.Height = 20;
lblfolder.Location = new Point(475, 39);
lblfolder.Font = font;
//lblfolder.ForeColor = Color.Blue;
lblfolder.Parent = this;
lblfolder.Height = 13;
lblfolder.Text = "Folders";
lblfile.Location = new Point(12, 39);
lblfile.Font = font;
//lblfile.ForeColor = ColorTranslator.FromHtml("#00ff00");
lblfile.Parent = this;
lblfile.Height = 13;
lblfile.Text = "Files";
lblpath.Location = new Point(12, 15);
lblpath.Font = font;
lblpath.ForeColor = ColorTranslator.FromHtml("#00ff00");
lblpath.Parent = this;
lblpath.Height = 13;
lblpath.Width = 30;
lblpath.Text = "Path";
scrollfolder.AutoScroll = false;
scrollfolder.HorizontalScroll.Enabled = false;
scrollfolder.HorizontalScroll.Visible = false;
scrollfolder.HorizontalScroll.Maximum = 0;
scrollfolder.AutoScroll = true;
scrollfolder.Parent = this;
scrollfolder.Height = 390;
scrollfolder.Width = 220;
scrollfolder.Location = new Point(x2 - 10, y - 10);
scrollfiles.AutoScroll = false;
scrollfiles.HorizontalScroll.Enabled = false;
scrollfiles.HorizontalScroll.Visible = false;
scrollfiles.HorizontalScroll.Maximum = 0;
scrollfiles.AutoScroll = true;
scrollfiles.Parent = this;
scrollfiles.Height = 390;
scrollfiles.Width = 420;
scrollfiles.Location = new Point(x - 10, y - 10);
}
You are missing # in color definition. It should be:
lblpath.ForeColor = ColorTranslator.FromHtml("#00ff00");
ColorTranslator.FromHtml will throw exception if "00ff00" used
Why don't you use the designer to set the colour?
Where did you add this code, to the constructor? Most likely, the statement throws an exception before InitializeComponents gets a chance to run - and if you added the code to the constructor, before InitializeComponents, it's very likely that lblpath doesn't exist yet, so you're getting NullReferenceException. Try enabling "break on all exceptions" in the debugger, it's very handy for debugging Winforms applications, since the error will no longer be swallowed.
Use the designer to set the colour, and you'll be fine.

GMap.Net zooming issue mouseovering / hovering a marker

When my cursor is over a marker, it doesn't zoom. Is there any way around this?
Cheers
public MainForm(Dictionary<string, string> startupParams)
{
InitializeComponent();
gMapControl.MapProvider = GMapProviders.GoogleMap;
gMapControl.Position = new PointLatLng(-33.861468, 151.209179);
gMapControl.MinZoom = 0;
gMapControl.MaxZoom = 24;
gMapControl.Zoom = 9;
gMapControl.MarkersEnabled = true;
gMapControl.DragButton = MouseButtons.Left;
gMapControl.ShowCenter = false;
}
private void UpdateMap()
{
gMapControl.Position = new PointLatLng(Convert.ToDouble(LatLng.Split(',')[0]), Convert.ToDouble(LatLng.Split(',')[1]));
GMapOverlay markersOverlay = new GMapOverlay("markers");
GMarkerGoogle marker = new GMarkerGoogle(new PointLatLng(Convert.ToDouble(LatLng.Split(',')[0]), Convert.ToDouble(LatLng.Split(',')[1])), GMarkerGoogleType.green);
markersOverlay.Markers.Add(marker);
gMapControl.Overlays.Clear();
gMapControl.Overlays.Add(markersOverlay);
}
Yes, there's a simple way around this:
gMapControl.IgnoreMarkerOnMouseWheel = true;

How to Change Content of Button if it is a child of a grid?

I want to change content of button1 on click event of button2 . But not able to get the object of grid's child Button class which is in List<> UiList.
Please Guide me in getting the right approach to look it and solve it . And also guide that if the object is build in runtime then how to access it ?
public partial class MainPage : PhoneApplicationPage
{
List<Grid> UIList = new List<Grid>();
Grid objGrid1 = null;
Button objButton1 = null;
Button objButton2 = null;
// Constructor
public MainPage()
{
InitializeComponent();
createGrid1("grid1");
createButton2("Button2");
}
public void createGrid1(string x)
{
objGrid1 = new Grid();
objGrid1.Height = 100;
objGrid1.Name = x;
objGrid1.Width = 200;
objGrid1.Margin = new Thickness(100, 100, 0, 0);
objGrid1.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
objGrid1.VerticalAlignment = System.Windows.VerticalAlignment.Top;
objGrid1.Background = new SolidColorBrush(Colors.Orange);
createButton1("changename");
}
public void createButton1(string _name)
{
objButton1 = new Button();
objButton1.Height = 90;
objButton1.Name = _name;
objButton1.Content="Button1";
objButton1.FontSize = 20;
objButton1.Width = 190;
objButton1.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
objButton1.VerticalAlignment = System.Windows.VerticalAlignment.Top;
objButton1.Background = new SolidColorBrush(Colors.Blue);
objButton1.Foreground = new SolidColorBrush(Colors.White);
objGrid1.Children.Add(objButton1);
LayoutRoot.Children.Add(objGrid1);
UIList.Add(objGrid1);
}
public void createButton2(string _name)
{
objButton2 = new Button();
objButton2.Margin = new Thickness(240, 300, 0, 0);
objButton2.Name = _name;
objButton2.Height = 90;
objButton2.Content = "Button2";
objButton2.FontSize = 20;
objButton2.Width = 190;
objButton2.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
objButton2.VerticalAlignment = System.Windows.VerticalAlignment.Top;
objButton2.Background = new SolidColorBrush(Colors.Blue);
objButton2.Foreground = new SolidColorBrush(Colors.White);
LayoutRoot.Children.Add(objButton2);
objButton2.Click += (s, e) =>
{
int c = UIList.ElementAt(0).Children.Count;
if (c == 1)
{
//logic to change content of Button1 on click of Button2
}
};
}
}
Assuming you cannot just keep a reference to the created control, such as in a class field, you can iterate through the Children property of the Grid and find the desired Button. If there are multiple buttons, you can differentiate them using the Tag property.
Once you find it, change the contents of the button using the Content property, as discussed in the contents above.

Categories

Resources