Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
KenPanCS
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
QCD
Tools
KenPanCS
Commits
f5a49be6
Commit
f5a49be6
authored
Nov 25, 2021
by
tsuji
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
・path入力のエラーによる処理中断時のメッセージ出力を追加
parent
bf94f167
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
123 additions
and
0 deletions
+123
-0
PageComboBox.cs
Code/CSRender/CSRender/PageComboBox.cs
+123
-0
No files found.
Code/CSRender/CSRender/PageComboBox.cs
0 → 100644
View file @
f5a49be6
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.Input
;
using
System.Windows.Media
;
using
System.Windows.Media.Imaging
;
using
System.Windows.Navigation
;
using
System.Windows.Shapes
;
using
System.Windows.Controls.Primitives
;
using
System.Text.RegularExpressions
;
namespace
CSRender
{
public
partial
class
MainWindow
:
Window
{
//コンボボックスの要素
public
class
ComboBoxSet
{
public
int
Id
{
get
;
set
;
}
public
string
Item
{
get
;
set
;
}
}
//クリックしたときに全体を選択
private
void
PageBox_GotFocusSelectAll
(
object
sender
,
RoutedEventArgs
e
)
{
TextBox
box
=
(
TextBox
)
sender
;
//box.SelectAll();
this
.
Dispatcher
.
InvokeAsync
(()
=>
{
Task
.
Delay
(
10
);
box
.
SelectAll
();
});
}
//ページ指定のプルダウンに応じてテキストボックスを活性化/非活性化
private
void
PageRange_SelectionChanged
(
object
sender
,
SelectionChangedEventArgs
e
)
{
var
SelectedItem
=
(
ComboBoxSet
)
PageRange
.
SelectedItem
;
if
(
SelectedItem
==
null
)
return
;
string
PageType
=
(
string
)
SelectedItem
.
Item
;
if
(
PageType
==
"指定"
)
{
pageBox
.
IsEnabled
=
true
;
pageLabel
.
IsEnabled
=
true
;
}
else
{
pageBox
.
IsEnabled
=
false
;
pageLabel
.
IsEnabled
=
false
;
}
}
//数字とハイフン、カンマ以外を無効化
private
void
PageBox_PreviewTextInput
(
object
sender
,
TextCompositionEventArgs
e
)
{
var
Pagebox
=
(
TextBox
)
sender
;
string
str
=
Pagebox
.
Text
;
//文字列
var
inputPage
=
e
.
Text
;
//入力された文字
//正規表現で入力文字の判定、数字とピリオド、カンマならtrue
bool
PageCheck
=
new
System
.
Text
.
RegularExpressions
.
Regex
(
"[0-9,-]"
).
IsMatch
(
inputPage
);
//入力文字が数値とカンマ、ハイフン以外だったら無効
if
(
PageCheck
==
false
)
{
e
.
Handled
=
true
;
//無効
return
;
//終了
}
//キャレット(カーソル)位置が先頭(0)であるときの、ハイフン入力は無効
if
(
Pagebox
.
CaretIndex
==
0
&&
inputPage
==
"-"
)
{
e
.
Handled
=
true
;
return
;
}
//キャレット(カーソル)位置が先頭(0)であるときの、カンマ入力は無効
if
(
Pagebox
.
CaretIndex
==
0
&&
inputPage
==
","
)
{
e
.
Handled
=
true
;
return
;
}
}
//誤ったハイフン・カンマの入力を修正
private
void
PageBox_LostFocus
(
object
sender
,
RoutedEventArgs
e
)
{
//ハイフン、カンマの削除
var
PageBox
=
(
TextBox
)
sender
;
string
inputText
=
PageBox
.
Text
;
// -,や,- は入力ミスなので後の文字だけ削除
inputText
=
inputText
.
Replace
(
"-,"
,
"-"
);
inputText
=
inputText
.
Replace
(
",-"
,
","
);
//先頭か末尾にあった場合は削除
if
(
inputText
.
StartsWith
(
","
)
||
inputText
.
EndsWith
(
","
))
{
inputText
=
inputText
.
TrimStart
(
','
);
inputText
=
inputText
.
TrimEnd
(
','
);
}
if
(
inputText
.
StartsWith
(
"-"
)
||
inputText
.
EndsWith
(
"-"
))
{
inputText
=
inputText
.
TrimStart
(
'-'
);
inputText
=
inputText
.
TrimEnd
(
'-'
);
}
PageBox
.
Text
=
inputText
;
}
private
void
PageBox_PreviewExecuted
(
object
sender
,
ExecutedRoutedEventArgs
e
)
{
//貼り付け無効
if
(
e
.
Command
==
ApplicationCommands
.
Paste
)
{
e
.
Handled
=
true
;
}
}
//スペースキーが押されたときは、それを無効にする
private
void
PageBox_PreviewKeyDown
(
object
sender
,
KeyEventArgs
e
)
{
if
(
e
.
Key
==
Key
.
Space
)
e
.
Handled
=
true
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment