MapWinGIS:SampleCode-C Sharp Net:ChangeGridColorSchemes

This is a back-up of the WIKI.
Not all links might work
We're working on a new wiki.

Main Page | Recent changes | View source | Page history | Log in / create account |

Printable version | Disclaimers | Privacy policy

Change Grid Color Scheme

This code first creates a new image for the specified grid with one color scheme, and then allows the user to toggle back and forth. The code is in two classes.

 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;
 
 namespace OCXTestCS
 {
     public partial class Form1 : Form
     {
         private GridColor gc;
         public Form1()
         {
             InitializeComponent();
             gc = new GridColor();
             gc.Map = axMap1;
         }
 
         private void cmdTest_Click(object sender, EventArgs e)
         {
             gc.ChangeColor();
         }
     }
 }

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Windows.Forms;
 using System.Drawing;
 namespace OCXTestCS
 {
     public class GridColor
     {
         
         private bool isBlue;
         MapWinGIS.GridColorScheme csBlue;
         MapWinGIS.GridColorScheme csRed;
         MapWinGIS.Grid grid;
         MapWinGIS.Utils utils;
         private AxMapWinGIS.AxMap map;
         private int layer = -1;
 
 
         public void ChangeColor()
         {
             // Open the file if one isn't open yet
             if (grid == null && OpenFile() == false) return;
             if (utils == null) utils = new MapWinGIS.Utils();
             MapWinGIS.GridColorScheme currentScheme;
             if (isBlue == false)
             {
                 if (csBlue == null)
                 {
                     csBlue = new MapWinGIS.GridColorScheme();
                     MapWinGIS.GridColorBreak Break1 = new MapWinGIS.GridColorBreak();
                     Break1.LowColor = RGB(0,0,255);
                     Break1.HighColor = RGB(120,120,255);
                     Break1.LowValue = Convert.ToDouble(grid.Minimum);
                     Break1.HighValue = Convert.ToDouble(grid.Maximum);
                     csBlue.InsertBreak(Break1);
                 }
                 currentScheme = csBlue;
                 isBlue = true;
             }
             else
             {
                 if (csRed == null)
                 {
                     csRed = new MapWinGIS.GridColorScheme();
                     MapWinGIS.GridColorScheme colorScheme1 = new MapWinGIS.GridColorScheme();
                     MapWinGIS.GridColorBreak Break1 = new MapWinGIS.GridColorBreak();
                     Break1.LowColor = RGB(255, 0, 0);
                     Break1.HighColor = RGB(255, 120, 120);
                     Break1.LowValue = Convert.ToDouble(grid.Minimum);
                     Break1.HighValue = Convert.ToDouble(grid.Maximum);
                     csRed.InsertBreak(Break1);
                 }
                 currentScheme = csRed;
                 isBlue = false;
             }
 
             if (layer > -1)
             {
                 map.SetImageLayerColorScheme(layer, currentScheme);
                 map.Refresh();
             }
            
             MapWinGIS.Image img = utils.GridToImage(grid, currentScheme, null);
             layer = Map.AddLayer(img, true);
 
             
           
            
             
             
         }
 
         public bool OpenFile()
         {
             OpenFileDialog ofd = new OpenFileDialog();
             grid = new MapWinGIS.Grid();
             ofd.Filter = grid.CdlgFilter;
             if (ofd.ShowDialog() != DialogResult.OK) return false;
             return grid.Open(ofd.FileName, MapWinGIS.GridDataType.UnknownDataType, true, MapWinGIS.GridFileType.UseExtension, null);
         }
 
         private UInt32 RGB(int red, int green, int blue)
         {
             return Convert.ToUInt32(blue * 256 * 256 + green * 256 + red);
         }
 
 
         public AxMapWinGIS.AxMap Map
         {
             get { return map; }
             set { map = value; }
         }
         
 
     }
 
  
 }


Code posted by Shade1974 on 11/24/2008

Retrieved from "http://mapwindow.org/wiki/index.php/MapWinGIS:SampleCode-C_Sharp_Net:ChangeGridColorSchemes"

This page has been accessed 1,459 times. This page was last modified on 24 November 2008, at 16:15.