自定義TextBox,實現自增自減

2021-10-01 08:43:02 字數 2120 閱讀 6748

我們使用附加屬性來實現,依賴屬性也可以實現,原理一樣

如圖xmal

cs,定義附加屬性

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.controls.primitives;

namespace textboxtest

public object convertback(object value, type targettype, object parameter, cultureinfo culture)

}/// /// 測試附加屬性

///

public class textboxhelper

public static void setisaddbuttonvisible(dependencyobject obj, bool value)

// using a dependencyproperty as the backing store for myproperty. this enables animation, styling, binding, etc...

public static readonly dependencyproperty isaddbuttonvisibleproperty =

dependencyproperty.registerattached("isaddbuttonvisible", typeof(bool), typeof(textboxhelper), new propertymetadata(ontextchanged));

public static bool getisremovebuttonvisible(dependencyobject obj)

public static void setisremovebuttonvisible(dependencyobject obj, bool value)

public static readonly dependencyproperty isremovebuttonvisibleproperty =

dependencyproperty.registerattached("isremovebuttonvisible", typeof(bool), typeof(textboxhelper), new propertymetadata(ontextchanged));

private static void ontextchanged(dependencyobject d, dependencypropertychangedeventargs e)

else

textbox.removehandler(button.clickevent, new routedeventhandler(buttonclicked));

textbox.addhandler(button.clickevent, new routedeventhandler(buttonclicked));

}/// /// 滑鼠滾輪

///

///

///

private static void textbox_mousewheel(object sender, system.windows.input.mousewheeleventargs e)

else

textbox.select(textbox.text.length, 0);//游標設定到文字尾部}}

private static void buttonclicked(object sender, routedeventargs e)

else

textbox.focus();

textbox.select(textbox.text.length, 0);}}

}}

使用

demo

mysql實現自定義sequence自增序列

mysql資料庫沒有oracle資料庫中sequence序列,mysql中只有auto increment自增,這種自增方式只能是整數型別的,如果要自定義的自增序列,mysql就不能實現。這裡,提供mysql實現自定義sequence自增序列的一種方法。drop table if exists se...

mysql 自定義自增序列

公司專案需求需要在一張包含自增主鍵的mysql表中,再次增加乙個自增字段,但是mysql只支援一張表乙個自增字段。create table if not exists sequence name varchar 50 not null,current value int 11 not null,in...

mysql 定義自增

alter table user table modify user id int unsigned auto increment 問題來了,為什麼我們要對我們的資料表作自增操作?因為當我們對錶設定為自增之後,我們以後若是想在表中插入資料的話,比如這個表是這樣的 userid username pa...