Skip to content

Commit

Permalink
adapt code in C#
Browse files Browse the repository at this point in the history
  • Loading branch information
changbowen committed Dec 10, 2016
1 parent f2a4779 commit 3b711ae
Show file tree
Hide file tree
Showing 11 changed files with 413 additions and 11 deletions.
Binary file modified .vs/DesktopNote/v14/.suo
Binary file not shown.
7 changes: 7 additions & 0 deletions DesktopNote.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Win_Search.xaml.cs">
<DependentUpon>Win_Search.xaml</DependentUpon>
</Compile>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand All @@ -74,6 +77,10 @@
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="Win_Search.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
Expand Down
12 changes: 12 additions & 0 deletions Win_Search.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Window x:Class="DesktopNote.Win_Search"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Search" Height="110" Width="310" MouseDown="Window_MouseDown" WindowStyle="None" Loaded="Window_Loaded" ShowInTaskbar="False" AllowsTransparency="True" Background="{x:Null}" Topmost="True" UseLayoutRounding="True">
<Grid Margin="10">
<Rectangle Fill="#FFDCF1FF" RadiusY="12" RadiusX="12" Opacity="0.7"/>
<TextBlock HorizontalAlignment="Left" Margin="10,13,0,0" TextWrapping="Wrap" Text="Search for" VerticalAlignment="Top"/>
<TextBox x:Name="TB_Search" HorizontalAlignment="Left" Height="23" Margin="91,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="191" TextChanged="TB_Search_TextChanged"/>
<Button x:Name="Btn_Search" Content="Search" HorizontalAlignment="Right" Margin="0,0,65,10" VerticalAlignment="Bottom" Width="50" IsDefault="True" Background="White" Height="25" Click="Btn_Search_Click"/>
<Button x:Name="Btn_Cancel" Content="Cancel" HorizontalAlignment="Right" Margin="0,0,10,10" VerticalAlignment="Bottom" Width="50" IsCancel="True" Background="White" Height="25" Click="Btn_Cancel_Click"/>
</Grid>
</Window>
101 changes: 101 additions & 0 deletions Win_Search.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;

namespace DesktopNote
{
/// <summary>
/// Interaction logic for Win_Search.xaml
/// </summary>
public partial class Win_Search : Window
{
private bool textchanged = true;

public Win_Search()
{
InitializeComponent();
}

private void MarkTextInRange(RichTextBox richTextBox, string searchText, bool searchNext)
{
//Get the range to search
TextRange searchRange;
if (searchNext)
searchRange = new TextRange(richTextBox.Selection.Start.GetPositionAtOffset(1), richTextBox.Document.ContentEnd);
else
searchRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);

TextPointer start = searchRange.Start.GetNextContextPosition(LogicalDirection.Forward);
while (start != null)
{
var txt = start.GetTextInRun(LogicalDirection.Forward);
if (txt.Length > 0)
{
int tgtindex = txt.IndexOf(searchText, StringComparison.OrdinalIgnoreCase);
if (tgtindex >= 0)
{
var selstart = start.GetPositionAtOffset(tgtindex);
var selend = start.GetPositionAtOffset(tgtindex + searchText.Length);
//if search string is at line start, non chars are included in below msgbox
//MsgBox(New TextRange(tgtptr, start.GetNextContextPosition(LogicalDirection.Forward)).Text)
((FrameworkContentElement)selstart.Parent).BringIntoView();
richTextBox.Selection.Select(selstart, selend);
richTextBox.Focus();
break;
}
}
start = start.GetNextContextPosition(LogicalDirection.Forward);
if (start == null)
{
textchanged = true;
MessageBox.Show("Search has reached the end of the document.", "", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
}

private void Window_Loaded(object sender, RoutedEventArgs e)
{
var mainwin = (MainWindow)Application.Current.MainWindow;
Left = mainwin.Left + (mainwin.Width - Width) / 2;
Top = mainwin.Top + (mainwin.Height - Height) / 2;
TB_Search.Focus();
}

private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left) DragMove();
}

private void TB_Search_TextChanged(object sender, TextChangedEventArgs e)
{
textchanged = true;
}

private void Btn_Search_Click(object sender, RoutedEventArgs e)
{
if (TB_Search.Text.Trim() == "")
Close();
else
{
var mainwin = (MainWindow)Application.Current.MainWindow;
if (textchanged)
{
textchanged = false;
MarkTextInRange(mainwin.RTB_Main, TB_Search.Text, false);
}
else
{
MarkTextInRange(mainwin.RTB_Main, TB_Search.Text, true);
}
Activate();
}
}

private void Btn_Cancel_Click(object sender, RoutedEventArgs e)
{
Close();
}
}
}
2 changes: 2 additions & 0 deletions obj/Debug/DesktopNote.csproj.FileListAbsolute.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ F:\GitHub Repos\DesktopNote\obj\Debug\MainWindow.g.cs
F:\GitHub Repos\DesktopNote\obj\Debug\App.g.cs
F:\GitHub Repos\DesktopNote\obj\Debug\DesktopNote_MarkupCompile.cache
F:\GitHub Repos\DesktopNote\obj\Debug\DesktopNote_MarkupCompile.lref
F:\GitHub Repos\DesktopNote\obj\Debug\Win_Search.baml
F:\GitHub Repos\DesktopNote\obj\Debug\Win_Search.g.cs
6 changes: 3 additions & 3 deletions obj/Debug/DesktopNote_MarkupCompile.cache
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ none
false
DEBUG;TRACE
F:\GitHub Repos\DesktopNote\App.xaml
11151548125
2-90453093

5-2017746502
6-55149600
14-53673721
MainWindow.xaml;
MainWindow.xaml;Win_Search.xaml;

True

8 changes: 4 additions & 4 deletions obj/Debug/DesktopNote_MarkupCompile.i.cache
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ none
false
DEBUG;TRACE
F:\GitHub Repos\DesktopNote\App.xaml
11151548125
2-90453093

9588776438
10-1743593956
14-53673721
MainWindow.xaml;
MainWindow.xaml;Win_Search.xaml;

True
False

4 changes: 0 additions & 4 deletions obj/Debug/DesktopNote_MarkupCompile.i.lref

This file was deleted.

Binary file added obj/Debug/Win_Search.baml
Binary file not shown.
142 changes: 142 additions & 0 deletions obj/Debug/Win_Search.g.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#pragma checksum "..\..\Win_Search.xaml" "{406ea660-64cf-4c82-b6f0-42d48172a799}" "60D5F737ADB076ED6A0D66C799181A8C"
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Effects;
using System.Windows.Media.Imaging;
using System.Windows.Media.Media3D;
using System.Windows.Media.TextFormatting;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Shell;


namespace DesktopNote {


/// <summary>
/// Win_Search
/// </summary>
public partial class Win_Search : System.Windows.Window, System.Windows.Markup.IComponentConnector {


#line 8 "..\..\Win_Search.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.TextBox TB_Search;

#line default
#line hidden


#line 9 "..\..\Win_Search.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.Button Btn_Search;

#line default
#line hidden


#line 10 "..\..\Win_Search.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.Button Btn_Cancel;

#line default
#line hidden

private bool _contentLoaded;

/// <summary>
/// InitializeComponent
/// </summary>
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
public void InitializeComponent() {
if (_contentLoaded) {
return;
}
_contentLoaded = true;
System.Uri resourceLocater = new System.Uri("/DesktopNote;component/win_search.xaml", System.UriKind.Relative);

#line 1 "..\..\Win_Search.xaml"
System.Windows.Application.LoadComponent(this, resourceLocater);

#line default
#line hidden
}

[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
switch (connectionId)
{
case 1:

#line 4 "..\..\Win_Search.xaml"
((DesktopNote.Win_Search)(target)).MouseDown += new System.Windows.Input.MouseButtonEventHandler(this.Window_MouseDown);

#line default
#line hidden

#line 4 "..\..\Win_Search.xaml"
((DesktopNote.Win_Search)(target)).Loaded += new System.Windows.RoutedEventHandler(this.Window_Loaded);

#line default
#line hidden
return;
case 2:
this.TB_Search = ((System.Windows.Controls.TextBox)(target));

#line 8 "..\..\Win_Search.xaml"
this.TB_Search.TextChanged += new System.Windows.Controls.TextChangedEventHandler(this.TB_Search_TextChanged);

#line default
#line hidden
return;
case 3:
this.Btn_Search = ((System.Windows.Controls.Button)(target));

#line 9 "..\..\Win_Search.xaml"
this.Btn_Search.Click += new System.Windows.RoutedEventHandler(this.Btn_Search_Click);

#line default
#line hidden
return;
case 4:
this.Btn_Cancel = ((System.Windows.Controls.Button)(target));

#line 10 "..\..\Win_Search.xaml"
this.Btn_Cancel.Click += new System.Windows.RoutedEventHandler(this.Btn_Cancel_Click);

#line default
#line hidden
return;
}
this._contentLoaded = true;
}
}
}

Loading

0 comments on commit 3b711ae

Please sign in to comment.