这里写自定义目录标题
效果图
xaml代码
<Window x:Class="WpfApp_HuaYiHotel.MoKuai.FangTai.MyColor"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp_HuaYiHotel.MoKuai.FangTai"
mc:Ignorable="d"
WindowStyle="None"
WindowStartupLocation="CenterScreen"
Background="Transparent"
AllowsTransparency="True"
Title="MyColor" Height="450" Width="550">
<Window.Resources>
<Style TargetType="TextBlock">
<Setter Property="FontSize" Value="17"></Setter>
</Style>
<!--<Style x:Key="cprct" TargetType="{x:Type Rectangle}">
<Setter Property="Width" Value="25"/>
<Setter Property="Height" Value="25"/>
<Setter Property="Margin" Value="1"/>
<Setter Property="Stroke" Value="Gray"/>
<Setter Property="StrokeThickness" Value="1"/>
<EventSetter Event="PreviewMouseLeftButtonDown" Handler="Rectangle_PreviewMouseLeftButtonDown"/>
</Style>-->
</Window.Resources>
<!--<Border VerticalAlignment="Center" Width="280" Background="#f0f0f0">
<StackPanel>
<WrapPanel HorizontalAlignment="Center">
<Rectangle Style="{StaticResource cprct}" Fill="White"/>
<Rectangle Style="{StaticResource cprct}" Fill="Gray"/>
<Rectangle Style="{StaticResource cprct}" Fill="Yellow"/>
<Rectangle Style="{StaticResource cprct}" Fill="Orange"/>
<Rectangle Style="{StaticResource cprct}" Fill="HotPink"/>
<Rectangle Style="{StaticResource cprct}" Fill="Peru"/>
<Rectangle Style="{StaticResource cprct}" Fill="RoyalBlue"/>
<Rectangle Style="{StaticResource cprct}" Fill="SkyBlue"/>
<Rectangle Style="{StaticResource cprct}" Fill="Teal"/>
<Rectangle Style="{StaticResource cprct}" Fill="Tomato"/>
<Rectangle Style="{StaticResource cprct}" Fill="Black"/>
<Rectangle Style="{StaticResource cprct}" Fill="Sienna"/>
<Rectangle Style="{StaticResource cprct}" Fill="Gold"/>
<Rectangle Style="{StaticResource cprct}" Fill="DarkBlue"/>
<Rectangle Style="{StaticResource cprct}" Fill="Magenta"/>
<Rectangle Style="{StaticResource cprct}" Fill="LimeGreen"/>
<Rectangle Style="{StaticResource cprct}" Fill="Lime"/>
<Rectangle Style="{StaticResource cprct}" Fill="Blue"/>
<Rectangle Style="{StaticResource cprct}" Fill="Green"/>
<Rectangle Style="{StaticResource cprct}" Fill="Red"/>
</WrapPanel>
<StackPanel Orientation="Horizontal" Height="30">
<TextBlock Text="ARGB:" VerticalAlignment="Center" Margin="16,0,10,0"/>
<TextBox Text="{Binding ElementName=cpicker, Path=SelectedColor, Mode=TwoWay}" VerticalAlignment="Center" Width="90"/>
<Rectangle Stroke="Gray" StrokeThickness="1" Width="80" Height="22" Margin="10,4,4,4"
Fill="{Binding ElementName=cpicker, Path=SelectedBrush}"/>
</StackPanel>
-->
<!--<local:ColorPicker x:Name="cpicker" SelectedColorChanged="cpicker_SelectedColorChanged"
SelectedColor="{Binding ElementName=clrctrl, Path= ExSelectedColor,Mode=OneWayToSource}"
SelectedBrush="{Binding ElementName= clrctrl,Path=ExSelectedBrush, Mode=TwoWay}" />-->
<!--
</StackPanel>
</Border>-->
<DockPanel>
<Border BorderThickness="5" Height="50" DockPanel.Dock="Top" Background="#FF8374E9" BorderBrush="#FF8374E9" CornerRadius="9,9,0,0" Margin="10,10,10,0">
<DockPanel>
<TextBlock Text="颜色修改" FontSize="23" Width="200" Foreground="White" Margin="10,0"></TextBlock>
<Border DockPanel.Dock="Right" BorderThickness="9">
<Image x:Name="image_GuanBi" Source="/Image/取消.png" />
</Border>
<Border></Border>
</DockPanel>
</Border>
<Border BorderThickness="5" Background="White" BorderBrush="White" CornerRadius="0,0,9,9" Margin="10,0,10,10">
<Border.Effect>
<DropShadowEffect ShadowDepth="4" BlurRadius="10" Direction="270" Color="#FF6B6A70"/>
</Border.Effect>
<Border BorderThickness="1">
<Border BorderBrush="#d3d3d3" BorderThickness="1" >
<DockPanel>
<Grid DockPanel.Dock="Top" Height="170">
<Canvas>
<!--调色板-->
<Border Canvas.Top="5" Canvas.Left="20">
<TextBlock Text="调色板" FontSize="17"></TextBlock>
</Border>
<Border x:Name="shiyan" Canvas.Top="25" Canvas.Left="20" BorderBrush="#d3d3d3" BorderThickness="5" Width="205" Height="143">
<Canvas>
<Image x:Name="imgColor" Stretch="Fill" Width="195" Height="133" MouseDown="ImgColor_MouseDown" MouseUp="ImgColor_MouseUp"></Image>
<Ellipse x:Name="ellColor" Canvas.Left="-4" Canvas.Bottom="-4" Width="8" Height="8" Fill="Transparent" Opacity="0.5" Stroke="White" StrokeThickness="1"/>
</Canvas>
</Border>
<Border Canvas.Top="5" Canvas.Right="1">
<TextBlock Text="明度选择"></TextBlock>
</Border>
<!--颜色选择器-->
<Border Canvas.Top="25" Canvas.Right="21" BorderBrush="#d3d3d3" BorderThickness="1" Width="20" Height="135">
<Canvas>
<Image x:Name="imgColorSelector" Stretch="Fill" Width="18" Height="133" MouseDown="ImgColorSelector_MouseDown" MouseUp="ImgColorSelector_MouseUp"></Image>
<Rectangle x:Name="rectColorSelector" Canvas.Left="0" Canvas.Top="129" Height="4" Width="18" Stroke="Red"></Rectangle>
</Canvas>
</Border>
<Border Canvas.Left="278" Canvas.Top="25">
<DockPanel>
<TextBlock DockPanel.Dock="Top" Text="当前颜色"></TextBlock>
<Border x:Name="SelectColor" Height="80" Width="130" BorderBrush="#d3d3d3" BorderThickness="1" ></Border>
</DockPanel>
</Border>
<Border Canvas.Top="133" Canvas.Left="278" Height="20" Width="130">
<DockPanel>
<TextBlock Text="颜色值:"></TextBlock>
<TextBlock x:Name="textBlock_DangQianYanSeZhi" Text="#FFFFFFFF" FontSize="13" VerticalAlignment="Center"></TextBlock>
</DockPanel>
</Border>
</Canvas>
</Grid>
<Border>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"></ColumnDefinition>
<ColumnDefinition Width="1*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1*"></RowDefinition>
<RowDefinition Height="5*"></RowDefinition>
<RowDefinition Height="1*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Text="颜色模板" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
<WrapPanel x:Name="wrappanel_color" Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Top" FlowDirection="LeftToRight">
<!--<Border x:Name="borderMyColor1" Height="35" Width="35" BorderBrush="Red" BorderThickness="1" Margin="7,5"/>
<Border x:Name="borderMyColor2" Height="35" Width="35" BorderBrush="Red" BorderThickness="1" Margin="7,5"/>
<Border x:Name="borderMyColor3" Height="35" Width="35" BorderBrush="Red" BorderThickness="1" Margin="7,5"/>
<Border x:Name="borderMyColor4" Height="35" Width="35" BorderBrush="Red" BorderThickness="1" Margin="7,5"/>
<Border x:Name="borderMyColor5" Height="35" Width="35" BorderBrush="Red" BorderThickness="1" Margin="7,5"/>
<Border x:Name="borderMyColor6" Height="35" Width="35" BorderBrush="Red" BorderThickness="1" Margin="7,5"/>
<Border x:Name="borderMyColor7" Height="35" Width="35" BorderBrush="Red" BorderThickness="1" Margin="7,5"/>
<Border x:Name="borderMyColor8" Height="35" Width="35" BorderBrush="Red" BorderThickness="1" Margin="7,5"/>
<Border x:Name="borderMyColor9" Height="35" Width="35" BorderBrush="Red" BorderThickness="1" Margin="7,5"/>
<Border x:Name="borderMyColor10" Height="35" Width="35" BorderBrush="Red" BorderThickness="1" Margin="7,5"/>
<Border x:Name="borderMyColor11" Height="35" Width="35" BorderBrush="Red" BorderThickness="1" Margin="7,5"/>
<Border x:Name="borderMyColor12" Height="35" Width="35" BorderBrush="Red" BorderThickness="1" Margin="7,5"/>
<Border x:Name="borderMyColor13" Height="35" Width="35" BorderBrush="Red" BorderThickness="1" Margin="7,5"/>
<Border x:Name="borderMyColor14" Height="35" Width="35" BorderBrush="Red" BorderThickness="1" Margin="7,5"/>
<Border x:Name="borderMyColor15" Height="35" Width="35" BorderBrush="Red" BorderThickness="1" Margin="7,5"/>-->
</WrapPanel>
<Border Grid.Row="0" Grid.Column="1">
<TextBlock Text="自定义颜色" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
</Border>
<WrapPanel x:Name="wrapPanelYanSeMoBan" Grid.Row="1" Grid.Column="1">
</WrapPanel>
<Button x:Name="button_QuXiao" Grid.Column="0" Grid.Row="2" Content="取消" Margin="0,2,0,0" FontSize="17" Style="{StaticResource ButtonStyle}"></Button>
<Button x:Name="button_QueRen" Grid.Column="1" Grid.Row="2" Content="确认" Margin="0,2,0,0" FontSize="17" Style="{StaticResource ButtonStyle}"></Button>
</Grid>
</Border>
</DockPanel>
</Border>
</Border>
</Border>
</DockPanel>
</Window>
c#代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Documents.DocumentStructures;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WpfApp_HuaYiHotel.Model;
namespace WpfApp_HuaYiHotel.MoKuai.FangTai
{
/// <summary>
/// MyColor.xaml 的交互逻辑
/// </summary>
public partial class MyColor : Window
{
private readonly Model.HuaYiHotel_SQLEntities myModel = new Model.HuaYiHotel_SQLEntities();
readonly System.Drawing.Bitmap baseBack;//底板位图对象
System.Drawing.Bitmap lightBmp;//亮度位图对象
System.Drawing.Bitmap ColorBmp;//色谱位图对象
System.Drawing.Color lightColor = System.Drawing.Color.Black;//亮度色谱
int ColorPx = -10, ColorPy = -10;//选择颜色的坐标
int lightP = 121;//选择亮度的坐标
readonly int ColorSelectorWidth = 18;//rectColorSelector的宽度值
readonly int ColorSelectorHeight = 129;//rectColorSelector的top值
public Color returnSelectColor;//选择的颜色
static public string DangQianYanSe;
readonly byte fangTaiID;
public MyColor(byte myfangTaiID)
{
InitializeComponent();
//ZiDingYiYanSe();
ColorUserDefined();
FuZhiWrapPanelYanSeMoBan();
fangTaiID = myfangTaiID;
SetColorBack();
SetlightBack();
baseBack = SetBaseColorBack();
ColorPx = 0;
ColorPy = 0;
returnSelectColor = Colors.Black;
//text_color.Text = Convert.ToString(returnSelectColor);
//text_color.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#003D3D3D"));
textBlock_DangQianYanSeZhi.Text = Convert.ToString(returnSelectColor);
SelectColor.Background = new SolidColorBrush(returnSelectColor);
//DangQianYanSe= Convert.ToString(returnSelectColor);
#region 事件绑定
image_GuanBi.MouseLeftButtonDown += Image_GuanBi_MouseLeftButtonDown;
button_QuXiao.Click += Button_QuXiao_Click;
button_QueRen.Click += Button_QueRen_Click;
//borderMyColor1.MouseRightButtonUp += BorderMyColor_MouseRightButtonUp;
//borderMyColor2.MouseRightButtonUp += BorderMyColor2_MouseRightButtonUp;
#endregion
}
private void ColorUserDefined()
{
string[] stringColorUserDefined =
{
Properties.Settings.Default.myColor1,
Properties.Settings.Default.myColor2,
Properties.Settings.Default.myColor3,
Properties.Settings.Default.myColor4,
Properties.Settings.Default.myColor5,
Properties.Settings.Default.myColor6,
Properties.Settings.Default.myColor7,
Properties.Settings.Default.myColor8,
Properties.Settings.Default.myColor9,
Properties.Settings.Default.myColor10,
Properties.Settings.Default.myColor11,
Properties.Settings.Default.myColor12,
Properties.Settings.Default.myColor13,
Properties.Settings.Default.myColor14,
Properties.Settings.Default.myColor15,
};
Border[] myBorder = new Border[stringColorUserDefined.Length];
for (int i = 0; i < stringColorUserDefined.Length; i++)
{
myBorder[i] = new Border()
{
Name = "borderColorUserDefined" + i.ToString(),
Height = 35,
Width = 35,
Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(stringColorUserDefined[i])),
Margin = new Thickness(7, 5, 7, 5),
BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("red"))
};
myBorder[i].MouseLeftButtonDown += ColorMoBan;
myBorder[i].MouseRightButtonDown += MyColor_MouseRightButtonDown;
wrapPanelYanSeMoBan.Children.Add(myBorder[i]);
}
}
private void MyColor_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
//Control col = this.myBorder.Controls.Find("控件名", true)[0];
//Button btn = col as Button;//转为Button
}
private void FuZhiWrapPanelYanSeMoBan()
{
string[] stringClolrMoBan = { "#FFFF1300", "#FFFF6F00", "#FFFFA200", "#FFFFD500", "#FFF2FB00", "#FF89E100", "#FF00CC2A", "#FF008DCC", "#FF003FCC", "#FF3400CC", "#FFA600CC", "#FFDD0061", "#FF99FFFF", "#FF6F66FF", "#FFF2FFBF" };
Border[] myBorder1 = new Border[stringClolrMoBan.Length];
for (int i = 0; i < stringClolrMoBan.Length; i++)
{
myBorder1[i] = new Border()
{
Name = "border_YanSeMoBan" + i.ToString(),
Height = 35,
Width = 35,
Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(stringClolrMoBan[i])),
//Tag = Convert.ToString(FangTaiBiao.Rows[i]["FangJianZhuangTaiID"])
Margin = new Thickness(7, 5, 7, 5),
BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("red"))
};
myBorder1[i].MouseLeftButtonDown += ColorMoBan; //Border_XianZhuZhuangTaiColor_MouseLeftButtonDown;
wrappanel_color.Children.Add(myBorder1[i]);
}
}
private void ColorMoBan(object sender, MouseButtonEventArgs e)
{
SelectColor.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(sender.GetType().GetProperty("Background").GetValue(sender).ToString()));
textBlock_DangQianYanSeZhi.Text = sender.GetType().GetProperty("Background").GetValue(sender).ToString();
}
//private void BorderMyColor2_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
//{
// borderMyColor2.Background = new SolidColorBrush(returnSelectColor);
// Properties.Settings.Default.myColor2 = Convert.ToString(returnSelectColor);
//}
//private void BorderMyColor_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
//{
// borderMyColor1.Background = new SolidColorBrush(returnSelectColor);
// Properties.Settings.Default.myColor1 = Convert.ToString(returnSelectColor);
//}
//public void ZiDingYiYanSe()
//{
// borderMyColor1.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(Properties.Settings.Default.myColor1));
// borderMyColor2.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(Properties.Settings.Default.myColor2));
//}
public void FangTaiYanSeGengGai(byte fangTaiID, string Color)
{
var fangTaiXinXi = (from tbFangJianZhuangTai in myModel.F_FangJianZhuangTai
where fangTaiID == tbFangJianZhuangTai.FangJianZhuangTaiID
select new
{
dbFangTaiMingCheng = tbFangJianZhuangTai.ZhuangTaiMingcCheng,
dbFangJianDaiMa = tbFangJianZhuangTai.ZhuangTaiDaiMa
}).SingleOrDefault();
try
{
//实例化对象
F_FangJianZhuangTai myFangJianZhuangTai = new F_FangJianZhuangTai
{
FangJianZhuangTaiID = fangTaiID,
YanSe = Color,
ZhuangTaiDaiMa = fangTaiXinXi.dbFangJianDaiMa,
ZhuangTaiMingcCheng = fangTaiXinXi.dbFangTaiMingCheng
};
myModel.Entry(myFangJianZhuangTai).State = System.Data.Entity.EntityState.Modified;
//保存修改
myModel.SaveChanges();
}
catch (Exception)
{
throw;
}
}
private void Button_QueRen_Click(object sender, RoutedEventArgs e)
{
//DangQianYanSe = Convert.ToString(returnSelectColor);
//string strMsg = "failed";
//try
//{
// //实例化对象
// SYS_Academe myAcademe = new SYS_Academe();
// //修改数据
// myAcademe.AcademeID = ID;
// myAcademe.AcademeName = Name;
// myAcademe.AcademeCode = Code;
// //获取和实质对象实体的状态=EntityState的枚举值
// myModels.Entry(myAcademe).State = EntityState.Modified;
// //保存修改
// myModels.SaveChanges();
// strMsg = "success";
//}
//catch (Exception)
//{
// strMsg = "failed";
//}
FangTaiYanSeGengGai(fangTaiID, DangQianYanSe);
this.Close();
}
private void Button_QuXiao_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void Image_GuanBi_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.Close();
}
/// <summary>
/// 获得色谱位图对象
/// </summary>
public void SetColorBack()
{
ColorBmp = new System.Drawing.Bitmap(205, ColorSelectorHeight);
_ = Colors.White;
int R = 255, G = 0, B = 0;
for (int i = 0; i < ColorSelectorHeight; i++)
{
for (int j = 0; j < 205; j++)
{
if (j >= 0 && j <= 34)
G = SetColorNum(G, j, true);
if (j > 34 && j <= 68)
R = SetColorNum(R, j, false);
if (j > 68 && j <= 102)
B = SetColorNum(B, j, true);
if (j > 102 && j <= 136)
G = SetColorNum(G, j, false);
if (j > 136 && j <= 170)
R = SetColorNum(R, j, true);
if (j > 170 && j <= 204)
B = SetColorNum(B, j, false);
int temps = i * -2;
int R2 = IntMaxMin(R + temps);
int G2 = IntMaxMin(G + temps);
int B2 = IntMaxMin(B + temps);
int l = Math.Max(0, lightP == 0 ? 255 : (121 - lightP) * 2);//lightP原始值
System.Drawing.Color tmpC = SetColorWhite(System.Drawing.Color.FromArgb(R2, G2, B2), l);
Color tempColor = Color.FromRgb(tmpC.R, tmpC.G, tmpC.B);
ColorBmp.SetPixel(j, i, System.Drawing.Color.FromArgb(tempColor.R, tempColor.G, tempColor.B));
}
}
}
/// <summary>
/// 设置色谱位图
/// </summary>
public System.Drawing.Bitmap SetBaseColorBack()
{
ColorBmp = new System.Drawing.Bitmap(205, ColorSelectorHeight);
_ = System.Drawing.Color.White;
int R = 255, G = 0, B = 0;
for (int i = 0; i < ColorSelectorHeight; i++)
{
for (int j = 0; j < 205; j++)
{
if (j >= 0 && j <= 34)
G = SetColorNum(G, j, true);
if (j > 34 && j <= 68)
R = SetColorNum(R, j, false);
if (j > 68 && j <= 102)
B = SetColorNum(B, j, true);
if (j > 102 && j <= 136)
G = SetColorNum(G, j, false);
if (j > 136 && j <= 170)
R = SetColorNum(R, j, true);
if (j > 170 && j <= 204)
B = SetColorNum(B, j, false);
int temps = i * -2;
int R2 = IntMaxMin(R + temps);
int G2 = IntMaxMin(G + temps);
int B2 = IntMaxMin(B + temps);
System.Drawing.Color tempColor = System.Drawing.Color.FromArgb(R2, G2, B2);
ColorBmp.SetPixel(j, i, tempColor);
}
}
//将Bitmap转换为BitmapSource
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(ColorBmp);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
ColorBmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
BitmapImage tempImage = new BitmapImage();
tempImage.BeginInit();
tempImage.StreamSource = new System.IO.MemoryStream(ms.ToArray());
tempImage.EndInit();
imgColor.Source = tempImage;
}
g.Dispose();
return ColorBmp;
}
/// <summary>
/// 设置亮度位图
/// </summary>
public void SetlightBack()
{
lightBmp = new System.Drawing.Bitmap(ColorSelectorWidth, ColorSelectorHeight);
for (int i = 0; i < ColorSelectorHeight; i++)
{
for (int j = 0; j < ColorSelectorWidth; j++)
{
System.Drawing.Color c = SetColorWhite(lightColor, Math.Max(255 - i * 2, 0));
lightBmp.SetPixel(j, i, c);
}
}
//将Bitmap转换为BitmapSource
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(lightBmp);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
lightBmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
BitmapImage tempImage = new BitmapImage();
tempImage.BeginInit();
tempImage.StreamSource = new System.IO.MemoryStream(ms.ToArray());
tempImage.EndInit();
imgColorSelector.Source = tempImage;
}
g.Dispose();
}
/// <summary>
/// 设置具体坐标的色彩值
/// </summary>
public int SetColorNum(int self, int y, bool isAdd)
{
int addnum = 8;
if (y == 0)
return self;
int num = isAdd ? self + addnum : self - addnum;
return IntMaxMin(num);
}
/// <summary>
/// 颜色变量区域限制
/// </summary>
public int IntMaxMin(int num)
{
if (num > 255)
return 255;
if (num < 0)
return 0;
return num;
}
/// <summary>
/// 设置颜色为白色
/// </summary>
public System.Drawing.Color SetColorWhite(System.Drawing.Color c, int white = 50)
{
int R = Math.Min(c.R + white, 255);
int G = Math.Min(c.G + white, 255);
int B = Math.Min(c.B + white, 255);
return System.Drawing.Color.FromArgb(R, G, B);
}
#region 调色板鼠标事件
private void ImgColor_MouseDown(object sender, MouseButtonEventArgs e)
{
imgColor.MouseMove += new MouseEventHandler(ImgColor_MouseMove);
SetColorPoint(e);
}
private void ImgColor_MouseMove(object sender, MouseEventArgs e)
{
SetColorPoint(e);
}
private void ImgColor_MouseUp(object sender, MouseButtonEventArgs e)
{
imgColor.MouseMove -= new MouseEventHandler(ImgColor_MouseMove);
}
/// <summary>
/// 同时设置颜色选择点位置
/// </summary>
public void SetColorPoint(MouseEventArgs e)
{
ColorPx = (int)(e.GetPosition(imgColor).X - 4);
ColorPy = (int)(e.GetPosition(imgColor).Y - 4);
if (ColorPx > ColorBmp.Width - 1)
ColorPx = ColorBmp.Width - 1;
if (ColorPx < 0)
ColorPx = 0;
if (ColorPy > ColorBmp.Height - 1)
ColorPy = ColorBmp.Height - 1;
if (ColorPy < 0)
ColorPy = 0;
ImgColorShowChange();
if (ColorPx >= 0 && ColorPx <= ColorBmp.Width && ColorPy >= 0 && ColorPy <= ColorBmp.Height)
{
lightColor = baseBack.GetPixel(ColorPx, ColorPy);
System.Drawing.Color tmpClor = ColorRight(ColorBmp.GetPixel(ColorPx, ColorPy));
returnSelectColor = Color.FromRgb(tmpClor.R, tmpClor.G, tmpClor.B);
//text_color.Text = Convert.ToString(returnSelectColor);
textBlock_DangQianYanSeZhi.Text = Convert.ToString(returnSelectColor);
SelectColor.Background = new SolidColorBrush(returnSelectColor);
DangQianYanSe = Convert.ToString(returnSelectColor);
SetlightBack();
}
}
private void ImgColorShowChange()
{
Canvas.SetTop(this.ellColor, ColorPy - 4);
Canvas.SetLeft(this.ellColor, ColorPx - 4);
}
/// <summary>
/// 颜色校正
/// </summary>
public System.Drawing.Color ColorRight(System.Drawing.Color c)
{
int R = IntMaxMin(c.R);
int G = IntMaxMin(c.G);
int B = IntMaxMin(c.B);
return System.Drawing.Color.FromArgb(R, G, B);
}
#endregion
#region 亮度调节鼠标事件
private void ImgColorSelector_MouseDown(object sender, MouseButtonEventArgs e)
{
imgColorSelector.MouseMove += new MouseEventHandler(ImgColorSelector_MouseMove);
SetLightPoint(e);
}
private void ImgColorSelector_MouseMove(object sender, MouseEventArgs e)
{
SetLightPoint(e);
}
private void ImgColorSelector_MouseUp(object sender, MouseButtonEventArgs e)
{
imgColorSelector.MouseMove -= new MouseEventHandler(ImgColorSelector_MouseMove);
}
/// <summary>
/// 同步设置亮度选择点位置
/// </summary>
public void SetLightPoint(MouseEventArgs e)
{
lightP = (int)(e.GetPosition(imgColorSelector).Y - 2);
if (lightP > ColorSelectorHeight)
lightP = ColorSelectorHeight;
if (lightP < 0)
lightP = 0;
SetColorBack();
ImgColorShowChange();
ImgColorSelectorChange();
if (ColorPx >= 0 && ColorPx <= ColorBmp.Width && ColorPy >= 0 && ColorPy <= ColorBmp.Height)
{
lightColor = baseBack.GetPixel(ColorPx, ColorPy);
System.Drawing.Color tmpClor = ColorRight(ColorBmp.GetPixel(ColorPx, ColorPy));
returnSelectColor = Color.FromRgb(tmpClor.R, tmpClor.G, tmpClor.B);
//text_color.Text = Convert.ToString(returnSelectColor);
textBlock_DangQianYanSeZhi.Text = Convert.ToString(returnSelectColor);
SelectColor.Background = new SolidColorBrush(returnSelectColor);
DangQianYanSe = Convert.ToString(returnSelectColor);
SetlightBack();
}
}
private void ImgColorSelectorChange()
{
Canvas.SetTop(this.rectColorSelector, lightP);
}
#endregion
}
}