模仿ArcGIS用Graphics重绘的直方图分级调节器




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
ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Controls;
using
ESRI.ArcGIS.Carto;

namespace 专题图自动化系统
{
    public partial class ColorMap
: Form
    {
       
double max, min;
        AxMapControl
axMapControl1;
        string
FindField;
        public ColorMap(double
_max,double _min,AxMapControl ax,string
findField)
       
{
           
InitializeComponent();
           
max =
_max;
            min
= _min;
           
axMapControl1 =
ax;
           
FindField = findField;
       
}
        IFeatureClass
pFeatureClass;
        private void
FindCity()
       
{
           
IFeatureLayer pFeatureLayer = axMapControl1.get_Layer(0) as
IFeatureLayer;
           
if (pFeatureLayer !=
null)
               
pFeatureClass =
pFeatureLayer.FeatureClass;
           
int[] index = new
int[2];//name字段+查询依据字段
           
for (int i = 0; i < index.Length;
i++)
           
{
               
if (i ==
0)
                   
index[i] =
pFeatureClass.Fields.FindField("name");
               
else
                   
index[i] =
pFeatureClass.Fields.FindField(FindField);
           
}
           
IFeatureCursor pFeatureCursor =
pFeatureClass.Search(null,false);
           
IFeature pFeature =
pFeatureCursor.NextFeature();
           
object [] value=new
object[index.Length];
           
while (pFeature !=
null)
           
{
               
for (int i = 0; i < index.Length;
i++)
               
{
                   
value[i] =
pFeature.get_Value(index[i]);
                   
if (i ==
1)
                   
{
                       
double  a =
Convert.ToDouble(value[1].ToString());
                       
switch
(searchCity.Length)
                       
{
                           
case 2: N1.Add(value[0].ToString());
break;
                           
case 3: if (a <= searchCity[1]) {
N1.Add(value[0].ToString());}
                           
else{N2.Add(value[0].ToString());}break;
                           
case 4: if (a <= searchCity[1]) { N1.Add(value[0].ToString());
}
                               
if (a > searchCity[1] && a <= searchCity[2]) {
N2.Add(value[0].ToString());
}
                               
if (a > searchCity[2]) { N3.Add(value[0].ToString());
}break;
                           
case 5: if (a <= searchCity[1]) { N1.Add(value[0].ToString());
}
                               
if (a > searchCity[1] && a <= searchCity[2]) {
N2.Add(value[0].ToString());
}
                               
if (a > searchCity[2]&&a<=searchCity[3]) {
N3.Add(value[0].ToString());
}
                               
if(a>searchCity[3]){N4.Add(value[0].ToString());}break;
                           
case 6: if (a <= searchCity[1]) { N1.Add(value[0].ToString());
}
                               
if (a > searchCity[1] && a <= searchCity[2]) {
N2.Add(value[0].ToString());
}
                               
if (a > searchCity[2] && a <= searchCity[3]) {
N3.Add(value[0].ToString());
}
                               
if (a > searchCity[3]&&a<=searchCity[4]) {
N4.Add(value[0].ToString());
}
                               
if(a>searchCity[4]){N5.Add(value[0].ToString());}break;
                       
}
                   
}
                    
               
}
               
pFeature =
pFeatureCursor.NextFeature();
           
}
       
}
        List<string> N1 = new
List<string>();
       
List<string> N2 = new
List<string>();
       
List<string> N3 = new
List<string>();
       
List<string> N4 = new
List<string>();
       
List<string> N5 = new
List<string>();
        private void
DrawCity()
       
{
            Bitmap
bt = new
Bitmap(panel3.Width,panel3.Height);
           
Graphics g =
Graphics.FromImage(bt);
           
Pen pen = new
Pen(Color.Black,1);
           
string []n1=new
string[6];
           
if (N1 !=
null)
           
{
               
foreach (string a in
N1)
               
{
                   
n1[1] += a +
",";
               
}
           
}
            if (N2
!= null)
           
{
               
foreach (string a in
N2)
               
{
                   
n1[2] += a +
",";
               
}
           
}
            if (N3
!= null)
           
{
               
foreach (string a in
N3)
               
{
                   
n1[3] += a +
",";
               
}
           
}
            if (N4
!= null)
           
{
               
foreach (string a in
N4)
               
{
                   
n1[4] += a +
",";
               
}
           
}
            if (N5
!= null)
           
{
               
foreach (string a in
N5)
               
{
                   
n1[5] += a +
",";
               
}
           
}
            for (int
i = 1; i <= n;
i++)
           
{
               
g.DrawString("第" + i + "级:" +n1[i], new Font("黑体", 10), new
SolidBrush(Color.Black), new PointF(20, 25 *
i));
           
}
           
panel3.BackgroundImage = bt;
       
}
        private void
DrawString()
       
{
            Bitmap
bt = new
Bitmap(panel2.Width,panel2.Height);
           
Graphics g =
Graphics.FromImage(bt);
           
Pen pen = new
Pen(Color.Black,1);
           
double fromValue =
min;
           
searchCity[0] =
fromValue;
           
double
toValue;
           
for (int i = 1; i <= n;
i++)
           
{
               
if (i ==
index)
                   
toValue = min + (x2 - temp[1]) * k /
flag;
               
else
                   
toValue=min + i *
k;
               
searchCity[i] =
toValue;
               
g.DrawString("第"+i+"级:"+fromValue+"万到"+toValue+"万",new Font("黑体",10),new
SolidBrush(Color.Black),new
PointF(20,25*i));
               
fromValue=toValue;
           
}
           
panel2.BackgroundImage = bt;
       
}
        double
k;
        private void
DrawZft()
       
{
            Bitmap
bt = new
Bitmap(panel1.Width,panel1.Height);
           
Graphics g =
Graphics.FromImage(bt);
           
Pen pen = new
Pen(Color.White,1);
           
g.DrawLine(pen,new Point(30,0),new
Point(30,panel1.Height-30));
           
g.DrawLine(pen,new Point(30,panel1.Height-30),new
Point(panel1.Width-4,panel1.Height-30));
           
k = (max - min) /
n;
            for
(int i = 1; i <= n+1;
i++)
           
{
               
if (i ==
index)
               
{
                   
g.DrawString((min + (x2-temp[1]) * k/flag).ToString(), new Font("宋体", 9), new
SolidBrush(Color.White), new PointF(x2 - 2,
panel1.Height-30));
                   
g.DrawLine(pen, new PointF(x2, panel1.Height-30), new PointF(x2,
0));
               
}
               
else
               
{
                   
g.DrawString((min + (i-1) * k).ToString(), new Font("宋体", 9), new
SolidBrush(Color.White), new PointF(temp[i] - 8,
panel1.Height-30));
                   
g.DrawLine(pen, new PointF(temp[i], panel1.Height-30), new PointF(temp[i],
0));
               
}
           
}
           
panel1.BackgroundImage = bt;
       
}
        int
n=0;
        float[]
temp;
        int
flag;
        double
[]searchCity;
        private void
comboBox1_SelectedIndexChanged(object sender, EventArgs
e)
       
{
            n =
int.Parse(comboBox1.SelectedItem.ToString());
           
temp = new float[n +
2];
           
searchCity=new
double[n+1];
           
flag = (panel1.Width - 4) / (n +
1);
            for
(int i = 1; i <= n+1;
i++)
           
{
               
temp[i] = flag *
i;
           
}
            if (N1
!=
null)
               
N1.Clear();
           
if (N2 !=
null)
               
N2.Clear();
           
if (N3 !=
null)
               
N3.Clear();
           
if (N4 !=
null)
               
N4.Clear();
           
if (N5 !=
null)
               
N5.Clear();
           
DrawZft();
           
DrawString();
           
FindCity();
           
DrawCity();
       
}
        int
index=0;
        int x1, x2,
x3;
        private void
panel1_MouseDown(object sender, MouseEventArgs
e)
       
{
            x1 =
e.X;
            for
(int i = 1; i < temp.Length;
i++)
           
{
               
if (Math.Abs(x1 - temp[i]) <
3)
               
{
                   
index =
i;
               
}
           
}
        }

private void
panel1_MouseMove(object sender, MouseEventArgs
e)
       
{
           
x2=e.X;
            if
(index !=
0)
           
{
               
if (N1 !=
null)
                   
N1.Clear();
               
if (N2 !=
null)
                   
N2.Clear();
               
if (N3 !=
null)
                   
N3.Clear();
               
if (N4 !=
null)
                   
N4.Clear();
               
if (N5 !=
null)
                   
N5.Clear();
               
DrawZft();
               
DrawString();
               
FindCity();
               
DrawCity();
           
}
        }

private void
panel1_MouseUp(object sender, MouseEventArgs
e)
       
{
            x3 =
e.X;
           
temp[index] =
x3;
           
DrawZft();
           
index = 0;
        }
   
}
}

模仿ArcGIS用Graphics重绘的直方图分级调节器,布布扣,bubuko.com

时间: 2024-08-03 20:36:08

模仿ArcGIS用Graphics重绘的直方图分级调节器的相关文章

C# 重绘tabControl,添加关闭按钮(页签)

#region 重绘tablecontrol const int CLOSE_SIZE = 15; //tabPage标签图片 Bitmap image = new Bitmap("D:\\power_003.png"); public void ClearPage() { //清空控件 //this.MainTabControl.TabPages.Clear(); //绘制的方式OwnerDrawFixed表示由窗体绘制大小也一样 this.tabControl1.DrawMode

Android学习Scroller(五)——详解Scroller调用过程以及View的重绘

MainActivity如下: package cc.ww; import android.os.Bundle; import android.widget.ImageView; import android.widget.ImageView.ScaleType; import android.widget.RelativeLayout; import android.widget.RelativeLayout.LayoutParams; import android.app.Activity;

android,view的重绘

============问题描述============ mars数独制作视频,页面重绘的时候出现了问题,"Unfortunately,shudu08 has stopped."感觉是某个xml文件没有配置好,求高手帮助纠正错误,顺便告诉下android运行的基本流程.我是纯小白,高手勿喷 进入界面: 点击空白处: 报错: 代码如下: Game.java package com.liuyuan.shudu08; public class Game { private final Str

窗体皮肤实现 - 重绘窗体非客户区(三)

窗体边框基本的绘制和控制完成,在第二篇中主要遗留的问题. 标题区域图标和按钮没绘制 缩放时客户区显示有问题 解决完下面的问题,皮肤处理基本完整.大致的效果GIF GIF中TShape的颜色表现有些问题,实际是正常的. 绘制标题区域内容 获取标题有效区域 绘制窗体图标 绘制按钮 绘制标题 标题区域主要考虑窗体是否在最大化状态,最大化后实际的标题绘制区域会有变化.可以通过 IsZoomed 或 GetWindowLong(Handle, GWL_STYLE) and WS_MAXIMIZE = WS

C# 自定义重绘DataGridView

using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Text; using System.Windows.Forms; using System.Drawing; using System.Runtime.CompilerServices; using System.Drawing.Drawing2D; na

C# 自定义重绘TextBox

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; using System.ComponentModel; namespace ControlExs.ControlExs.TextBoxEx { public cl

C# 自定义重绘TabControl

using System.Drawing; using System.Windows.Forms; using System.Drawing.Drawing2D; using System.Runtime.InteropServices; using System; using System.Drawing.Text; using System.ComponentModel; namespace ControlExs.ControlExs.CTabControl { public class C

DataGridView重绘painting简单实例

private void dataGridViewX1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { if (e.RowIndex >= 0 && e.ColumnIndex>=0) { Rectangle newRect = new Rectangle(e.CellBounds.X, e.CellBounds.Y, e.CellBounds.Width - 1, e.CellBounds.

WinForm中重绘TabControl选项卡标题

最近开发WinForm频繁使用了TabControl控件,这个控件的选项卡没有BackgroundImage这个属性,那么如何为其各个选项卡添加背景图片呢?(这里说的是每个TabPage的头部,也就是标题,不是工作区域.) 最开始用到TabControl的时候,我的每个选项卡是写死的,而后由于项目需求又动态添加了TabControl并生成各个选项卡,而两次我都要重绘其标题,因此在这里把我当时两种情形下重绘的方法通过一个例子一起分享出来. 首先先在窗体拖个Tabcontrol控件,然后更改了其Al