PDA

View Full Version : سوال: تکست باکس بی رنگ



mg_mahyar
پنج شنبه 03 آذر 1390, 20:58 عصر
سلام
چطوری میشه رنگ تکست باکس رو از بین برد؟ و بی رنگش کرد؟ یعنی دیگه سفید نباشه و کلا رنگی نباشه.

Amir Oveisi
پنج شنبه 03 آذر 1390, 21:54 عصر
خوب باید خودتون usercontrol‌بسازید. اما قبلا این کار شده:
http://www.codeproject.com/KB/edit/AlphaBlendedTextControls.aspx

mg_mahyar
پنج شنبه 03 آذر 1390, 22:27 عصر
مشکل همینه من الان دکمه و بقیه چیزا رو ساختم ولی تکست باکس رو هر کاری میکنم خطا میده و سیاه میشه
ممنون از پیشنهادت میرم ببینم این کد اجرا میشه یا نه

mg_mahyar
جمعه 04 آذر 1390, 13:41 عصر
http://www.codeproject.com/KB/edit/alphablendtextbox.aspx
قبلی یه نمه مورد داشت ولی از اون به لینک بالا رسیدم
ولی هنوز مشکل دارم. این مال دات نت 1 هست ظاهرا الان راه بهتری نداریم؟یه چیزی تو این مایه ها
public class Textbox1 : System.Windows.Forms.TextBox
{
public Textbox1()
{
SetStyle(System.Windows.Forms.ControlStyles.Suppor tsTransparentBackColor, true);
this.BackColor = System.Drawing.Color.Transparent;
}

Amir Oveisi
جمعه 04 آذر 1390, 13:56 عصر
از فایلی که ضمیمه کردم استفاده کنید.
نحوه کارش مثل TextBox معمولی هست و یک property جدید به اسم alpha‌داره که میتونید با صفر کردن اون transparent‌ کنید background اش رو.
موفق باشید

mg_mahyar
جمعه 04 آذر 1390, 14:03 عصر
ممنون ولی اینو خودمم داشتم .
بحث اینه واقعا نمیشه با کد کمتری این کارو کرد؟ همون دیشب که لینک دادی مشکل حل شد ولی تعداد خطوط کد زیاده. من پنل یا دکمه رو با چند خط کد تونستم شیشه ای کنم ولی textbox رو نشد.
این dll شما هم ظاهرا داره از یک picturebox استفاده میکنه در پشت قضیه. و اون داره پاس میده. و این مال دات نت دو هست. الان که دات نت 4 هست راه بهتری براش نیست؟

Amir Oveisi
جمعه 04 آذر 1390, 15:00 عصر
دات نت ۴ ساختار کنترل ها رو تغییر نداده که راه جدیدی برای این کار وجود داشته باشه.
باید از همین روش استفاده کنید. به دلیل نحوه render‌کردن مفهموم transparent در ویندوز؛ text box نمیتونه ذاتا transparent باشه. بنابراین باید کنترلی بسازید که این قابلیت رو داشته باشه. حالا اگر از کنترل دیگه ای در ساختن کنترل جدید استفاده بشه مشکلی وجود نداره.

exlord
جمعه 04 آذر 1390, 19:23 عصر
textbox توی دات نت فقط یه wrapper دور کنترل win32 هست و نمیشه دستکتریش کرد باید بشینین خودتون از صفر به کنترل بنویسین ... من یه کنترل نوشتم ولی کامل نیست و فقط امکانات اولیه یه textbox رو داره ... و وقت تکمیل کردنشو ندارم ...

mg_mahyar
جمعه 04 آذر 1390, 20:10 عصر
اگر بزارید همونو من تکمیل میکنم. البته اگر ممکن باشه.
من الان لیبل رو گسترش دادم میشه جای تکسباکس استفاده کرد ولی یه مقدار مشکلات داره. مثلا وقتی کاربر با tab کیبرد بخواد بین کنترلر ها سوییچ کنه قاطی میکنه و از از لیبل مورد نظرم میپره. و ضمن اینکه یه مقدار زیادی وابسه به ویندوزه و از از اصل دات نت دوره.

exlord
جمعه 04 آذر 1390, 21:11 عصر
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;
using System.Drawing.Drawing2D;

namespace Exlord.Controls
{
public class ExTextBox : Control
{
private Color _gColor1;
private Color _gColor2;
private Int16 _glassOpacity;
private Int16 _borderThickness;
private Rectangle _backgroungBounds
{
get
{
return new Rectangle(
this.BorderThickness,
this.BorderThickness,
this.Width - (this.BorderThickness * 2),
this.Height - (this.BorderThickness * 2)
);
}
}
private Timer _blinkTimer;
private bool _blink;

public Color GradiantGlassStartColor
{
get
{
return this._gColor1;
}
set
{
this._gColor1 = value;
this.Invalidate();
}
}
public Color GradiantGlassEndColor
{
get
{
return this._gColor2;
}
set
{
this._gColor2 = value;
this.Invalidate();
}
}
public Int16 GlassOpacity
{
get
{
return this._glassOpacity;
}
set
{
this._glassOpacity = value;
this.Invalidate();
}
}
public Int16 BorderThickness
{
get
{
return this._borderThickness;
}
set
{
this._borderThickness = value;
this.Invalidate();
}
}
public Color BorderColor { get; set; }

public ExTextBox()
{
this.GradiantGlassStartColor = Color.White;
this.GradiantGlassEndColor = Color.Green;
this.BorderColor = Color.White;
this.GlassOpacity = 70;
this.BorderThickness = 1;
this.Width = 100;
this.Height = 30;
this.Cursor = Cursors.IBeam;
this.SetStyle(
ControlStyles.AllPaintingInWmPaint |
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.ResizeRedraw |
ControlStyles.SupportsTransparentBackColor |
ControlStyles.UserPaint, true);
this.BackColor = Color.Transparent;

_blinkTimer = new Timer();
_blinkTimer.Interval = 500;
_blinkTimer.Tick += new EventHandler(_blinkTimer_Tick);

}

void _blinkTimer_Tick(object sender, EventArgs e)
{
_blink = !_blink;
this.Invalidate();
}

protected override void OnPaintBackground(PaintEventArgs e)
{
base.OnPaintBackground(e);
e.Graphics.FillRectangle(
new LinearGradientBrush(
new PointF(this.Width / 2, 0),
new PointF(this.Width / 2, this.Height),
Color.FromArgb(this.GlassOpacity, this.GradiantGlassStartColor),
Color.FromArgb(this.GlassOpacity, this.GradiantGlassEndColor)
),
this._backgroungBounds);
}
protected void OnPaintCursor(PaintEventArgs e)
{
if (_blink)
{
float x = e.Graphics.MeasureString(this.Text, this.Font).Width + this.BorderThickness + 2;
float y1 = this.BorderThickness + 2;
float y2 = e.Graphics.MeasureString("A", this.Font).Height;
e.Graphics.DrawLine(Pens.Black, new PointF(x, y1), new PointF(x, y2));
}

}
protected void OnPaintBorder(PaintEventArgs e)
{
e.Graphics.DrawRectangle(
new Pen(this.BorderColor, this.BorderThickness),
new Rectangle(0, 0, this.Width - 1, this.Height - 1)
);
}
protected void OnPaintText(PaintEventArgs e)
{
e.Graphics.DrawString(
this.Text,
this.Font,
Brushes.Black,
new RectangleF(
new PointF(
this.BorderThickness + 1,
this.BorderThickness + 1),
e.Graphics.MeasureString(this.Text, this.Font)));
}
protected override void OnPaint(PaintEventArgs e)
{
//this.Height = (int)e.Graphics.MeasureString("A", this.Font).Height + this.BorderThickness + 1;
OnPaintBorder(e);
OnPaintText(e);
OnPaintCursor(e);
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
//this.Invalidate();
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Back)
{
if (this.Text.Length > 0)
this.Text = this.Text.Substring(0, this.Text.Length - 1);
}
else
this.Text += e.KeyChar;
this.Invalidate();
}
protected override void OnGotFocus(EventArgs e)
{
_blinkTimer.Start();
base.OnGotFocus(e);
}
protected override void OnLostFocus(EventArgs e)
{
_blinkTimer.Stop();
_blink = false;
base.OnLostFocus(e);
}
protected override void OnClick(EventArgs e)
{
this.Focus();
base.OnClick(e);
}
protected override void OnMouseDown(MouseEventArgs e)
{

}
}
}

mg_mahyar
شنبه 05 آذر 1390, 07:46 صبح
ممنون من به نظرم این عالی بود فقط یه مشکل داشت اونم نشانگر کرزر بود که وقتی چند تا تکس باکس باشه تو همش نشون میده. جز اون اگر مشکلی داره یا پیشنهادی داره بفرمایید تا اصلاح کنم.

m2_farzan
یک شنبه 06 آذر 1390, 16:10 عصر
بهترین و استاندارد ترین راه برای شما اینه:WPF!:چشمک: